当前位置: 首页>>代码示例>>PHP>>正文


PHP file_move函数代码示例

本文整理汇总了PHP中file_move函数的典型用法代码示例。如果您正苦于以下问题:PHP file_move函数的具体用法?PHP file_move怎么用?PHP file_move使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了file_move函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addStreamFormSubmit

 function addStreamFormSubmit($form_id, $form_values)
 {
     module_load_include('inc', 'Fedora_Repository', 'api/fedora_utils');
     module_load_include('inc', 'Fedora_Repository', 'api/fedora_item');
     module_load_include('php', 'Fedora_Repository', 'ObjectHelper');
     $types = array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.wordperfect', 'application/wordperfect', 'application/vnd.oasis.opendocument.text', 'text/rtf', 'application/rtf', 'application/msword', 'application/vnd.ms-powerpoint', 'application/pdf');
     global $user;
     /* TODO Modify the validators array to suit your needs.
        This array is used in the revised file_save_upload */
     $fileObject = file_save_upload('file_uploaded');
     if (!in_array($fileObject->filemime, $types)) {
         drupal_set_message(t('The detected mimetype %s is not supported', array('%s' => $fileObject->filemime)), 'error');
         return false;
     }
     file_move($fileObject->filepath, 0, 'FILE_EXISTS_RENAME');
     $objectHelper = new ObjectHelper();
     $pid = $form_values['pid'];
     $fedora_item = new Fedora_Item($pid);
     $test = NULL;
     $test = $fedora_item->add_datastream_from_file($fileObject->filepath, 'OBJ');
     if ($test) {
         $this->updateMODSStream($form_values['pid'], $form_values['version'], $form_values['usage']);
     }
     file_delete($fileObject->filepath);
     return true;
 }
开发者ID:roblib,项目名称:islandora_scholar_upei,代码行数:26,代码来源:IrClass.php

示例2: generateValues

 public function generateValues($object, $instance, $plugin_definition, $form_display_options)
 {
     static $file;
     $settings = $instance->getFieldSettings();
     if (empty($file)) {
         if ($path = $this->generateTextFile()) {
             $source = new stdClass();
             $source->uri = $path;
             $source->uid = 1;
             // TODO: randomize? use case specific.
             $source->filemime = 'text/plain';
             $source->filename = drupal_basename($path);
             $destination_dir = $settings['uri_scheme'] . '://' . $settings['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . '/' . basename($path);
             $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
         } else {
             return FALSE;
         }
     }
     if (!$file) {
         // In case a previous file operation failed or no file is set, return FALSE
         return FALSE;
     } else {
         $object_field['target_id'] = $file->id();
         $object_field['display'] = $settings['display_default'];
         $object_field['description'] = DevelGenerateBase::createGreeking(10);
         return $object_field;
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:30,代码来源:DevelGenerateFieldFile.php

示例3: _os_files_deprivatize_file

/**
 * Moves a private managed file to the public directory.
 */
function _os_files_deprivatize_file($fid)
{
    $file = file_load($fid);
    // Builds new public path.
    $dest_uri = str_replace('private://', 'public://', $file->uri);
    $dest_path = _os_files_deprivatize_get_dest_path($dest_uri);
    // Creates the destination folder if it doesn't exist.
    if (!is_dir($dest_path)) {
        // Creates the folder.
        drupal_mkdir($dest_path, NULL, TRUE);
    }
    $moved_file = @file_move($file, $dest_uri);
    if ($moved_file) {
        drush_log(dt('File @name moved successfully.', array('@name' => $file->filename)), 'success');
    } else {
        drush_log(dt('Error moving file @name.', array('@name' => $file->filename)), 'error');
        return FALSE;
    }
    $file->uri = $moved_file->uri;
    $file_moved = file_save($file);
    if (isset($file_moved->fid)) {
        drush_log(dt('[O] File @name updated successfully.', array('@name' => $file->filename)), 'success');
        return TRUE;
    } else {
        drush_log(dt('[!] Error updating file @name.', array('@name' => $file->filename)), 'error');
        return FALSE;
    }
}
开发者ID:aleph-n,项目名称:opencholar,代码行数:31,代码来源:deprivatize.php

示例4: generateImage

 public function generateImage($object, $field, $instance, $bundle)
 {
     static $images = array();
     $min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
     $max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
     $extension = 'jpg';
     if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
         if ($tmp_file = drupal_tempnam('temporary://', 'imagefield_')) {
             $destination = $tmp_file . '.' . $extension;
             file_unmanaged_move($tmp_file, $destination, FILE_EXISTS_REPLACE);
             $min = explode('x', $min_resolution);
             $max = explode('x', $max_resolution);
             $max[0] = $max[0] < $min[0] ? $min[0] : $max[0];
             $max[1] = $max[1] < $min[1] ? $min[1] : $max[1];
             $width = rand((int) $min[0], (int) $max[0]);
             $height = rand((int) $min[1], (int) $max[1]);
             $gray = isset($this->settings['devel_image_provider_gray']) ? $this->settings['devel_image_provider_gray'] : NULL;
             $tags = isset($this->settings['devel_image_provider_tags']) ? $this->settings['devel_image_provider_tags'] : NULL;
             $url = "{$this->provider_base_url}/{$width}/{$height}";
             if (!empty($tags)) {
                 $url .= '/' . $tags;
             }
             $url = $gray ? $url . '/bw' : $url;
             // Generate seed value.
             $seed = isset($this->settings['devel_image_provider_seed']) ? $this->settings['devel_image_provider_seed'] : NULL;
             $rand_value = rand(0, $seed);
             $url .= '/' . $rand_value;
             $method = isset($this->settings['devel_image_provider_get_method']) ? $this->settings['devel_image_provider_get_method'] : 'file_get_contents';
             $path = devel_image_provider_get_file($url, $destination, $method);
             $source = new stdClass();
             $source->uri = $path;
             $source->uid = 1;
             // TODO: randomize? Use case specific.
             $source->filemime = 'image/jpg';
             if (!empty($instance['settings']['file_directory'])) {
                 $instance['settings']['file_directory'] = $instance['settings']['file_directory'] . '/';
             }
             $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . basename($path);
             $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
         } else {
             return FALSE;
         }
     } else {
         // Select one of the images we've already generated for this field.
         $file = new stdClass();
         $file->fid = array_rand($images[$extension][$min_resolution][$max_resolution]);
     }
     $object_field['fid'] = $file->fid;
     $object_field['alt'] = devel_create_greeking(4);
     $object_field['title'] = devel_create_greeking(4);
     return $object_field;
 }
开发者ID:kreynen,项目名称:elmsln,代码行数:54,代码来源:FlickholdrProvider.class.php

示例5: testTokensMoved

  /**
   * Test token values with a moved text file.
   */
  public function testTokensMoved() {
    // Prepare a test text file.
    /** @var \Drupal\file\Entity\File $text_file */
    $text_file = $this->getTestFile('text');
    $text_file->save();

    // Move the text file.
    $moved_file = file_move($text_file, 'public://moved.diff');

    // Ensure tokens are processed correctly.
    $data = ['file' => $moved_file];
    $this->assertToken('[file:ffp-name-only]', 'moved', $data);
    $this->assertToken('[file:ffp-name-only-original]', 'text-0', $data);
    $this->assertToken('[file:ffp-extension-original]', 'txt', $data);
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:18,代码来源:FileFieldPathsTokensTest.php

示例6: bulkSavePictures

function bulkSavePictures(&$form_state)
{
    $num_files = count($_FILES['files']['name']);
    for ($i = 0; $i < $num_files; $i++) {
        $file = file_save_upload($i, array('file_validate_is_image' => array(), 'file_validate_extensions' => array('png gif jpg jpeg')));
        if ($file) {
            if ($file = file_move($file, 'public://')) {
                $form_state['values']['file'][$i] = $file;
            } else {
                form_set_error('file', t('Failed to write the uploaded file the site\'s file folder.'));
            }
        } else {
            form_set_error('file', t('No file was uploaded.'));
        }
    }
}
开发者ID:ChapResearch,项目名称:CROMA,代码行数:16,代码来源:pictureFunctions.php

示例7: test_file

 public function test_file()
 {
     $file1 = self::getDir() . '/dir1/foo.txt';
     $file2 = self::getDir() . '/dir2/bar.txt';
     $file3 = self::getDir() . '/dir2/baz.txt';
     $file3_name = 'baz.txt';
     $file4 = self::getDir() . '/dir4/yolo.txt';
     $this->assertFalse(file_exists($file1));
     file_create($file1);
     file_write($file1, '');
     $this->assertTrue(file_exists($file1));
     $this->assertEquals('', file_read($file1));
     file_write($file1, 'foo');
     $this->assertEquals('foo', file_read($file1));
     file_append($file1, '_bar');
     $this->assertEquals('foo_bar', file_read($file1));
     file_prepend($file1, '#');
     $this->assertEquals('#foo_bar', file_read($file1));
     file_append($file1, '_bar');
     file_prepend($file1, '#');
     $this->assertEquals('##foo_bar_bar', file_read($file1));
     file_append($file1 . '_append', '_bar');
     $this->assertEquals(file_read($file1 . '_append'), '_bar');
     file_prepend($file1 . '_prepend', '#');
     $this->assertEquals(file_read($file1 . '_prepend'), '#');
     $this->assertFalse(file_exists($file2));
     file_copy($file1, $file2);
     $this->assertTrue(file_exists($file2));
     $this->assertEquals(file_read($file1), file_read($file2));
     $this->assertFalse(file_exists($file3));
     file_rename($file2, $file3_name);
     $this->assertFalse(file_exists($file2));
     $this->assertTrue(file_exists($file3));
     $this->assertEquals(file_read($file1), file_read($file3));
     $this->assertFalse(file_exists($file4));
     file_move($file3, $file4);
     $this->assertFalse(file_exists($file3));
     $this->assertTrue(file_exists($file4));
     $this->assertEquals(file_read($file1), file_read($file4));
     file_delete($file4);
     file_delete($file4);
     $this->assertFalse(file_exists($file4));
     $this->assertEquals(self::getDir() . '/dir1', file_get_directory($file1));
     $this->assertEquals('txt', file_get_extension($file1));
     $this->assertEquals('foo.txt', file_get_name($file1));
 }
开发者ID:weew,项目名称:helpers-filesystem,代码行数:46,代码来源:FileTest.php

示例8: testNormal

 /**
  * Tests moving a randomly generated image.
  */
 function testNormal()
 {
     // Pick a file for testing.
     $file = File::create((array) current($this->drupalGetTestFiles('image')));
     // Create derivative image.
     $styles = ImageStyle::loadMultiple();
     $style = reset($styles);
     $original_uri = $file->getFileUri();
     $derivative_uri = $style->buildUri($original_uri);
     $style->createDerivative($original_uri, $derivative_uri);
     // Check if derivative image exists.
     $this->assertTrue(file_exists($derivative_uri), 'Make sure derivative image is generated successfully.');
     // Clone the object so we don't have to worry about the function changing
     // our reference copy.
     $desired_filepath = 'public://' . $this->randomMachineName();
     $result = file_move(clone $file, $desired_filepath, FILE_EXISTS_ERROR);
     // Check if image has been moved.
     $this->assertTrue(file_exists($result->getFileUri()), 'Make sure image is moved successfully.');
     // Check if derivative image has been flushed.
     $this->assertFalse(file_exists($derivative_uri), 'Make sure derivative image has been flushed.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:24,代码来源:FileMoveTest.php

示例9: imglist_main

function imglist_main()
{
    global $print, $x7s, $x7c, $x7p;
    $base_image_dir = "/images/";
    $image_dir = "/images/";
    if (isset($_GET['subdir']) && $_GET['subdir'] != "") {
        $image_dir .= $_GET['subdir'] . "/";
    }
    if ($x7c->permissions['admin_panic'] || authorized($image_dir, $x7p->profile['usergroup'])) {
        $basedir = dirname($_SERVER['DOCUMENT_ROOT'] . $_SERVER['PHP_SELF']);
        $file_path = $basedir . $image_dir;
        $image_root_dir = $basedir . $base_image_dir;
        $error = "<p style=\"color: red; font-weight: bold;\">";
        if (isset($_GET['file'])) {
            $error .= file_upload($file_path);
        } elseif (isset($_GET['delete'])) {
            $error .= file_delete($file_path . $_GET['delete']);
        } elseif (isset($_POST['multidel'])) {
            if ($_POST['action'] == 'delete') {
                foreach ($_POST['multidel'] as $file) {
                    $error .= file_delete($file_path . $file);
                }
            } elseif ($_POST['action'] == 'move') {
                foreach ($_POST['multidel'] as $file) {
                    $error .= file_move($file_path . $file, $image_root_dir . $_POST['dest'] . $file);
                }
            }
        }
        $error .= "</p>";
        $site_path = dirname($_SERVER['PHP_SELF']) . $image_dir;
        $output = file_list($file_path, $site_path);
        $body = $error . $output['body'];
        $head = $output['head'];
        $print->normal_window($head, $body);
    } else {
        return "Non sei autorizzato a vedere questa pagina <br>";
    }
}
开发者ID:EZDM,项目名称:omeyocan,代码行数:38,代码来源:imglist.php

示例10: saveFile

 /**
  * Save uploaded file. Call this from the form submit handler
  * @return
  * 		true if success, false if not
  * @param object $file_field[optional]
  * 		field name of the form
  * @param object $file_type[optional]
  * 		acceptable MIME type substring, e.g. 'image/'
  */
 function saveFile($file_field = 'attachment', $file_type = '')
 {
     if (isset($_FILES[$file_field]) && !empty($_FILES[$file_field]['name'])) {
         // we only care about single file uploads here
         $uploadkey = '';
         //the original name of the file is $_FILES[$file_field]['name'][$upload_key]
         if (is_array($_FILES[$file_field]['name'])) {
             foreach ($_FILES[$file_field]['name'] as $key => $val) {
                 $uploadkey = $key;
                 break;
             }
         }
         // valid attachment ?
         if ($file_type != '') {
             if (!eregi($file_type, $uploadkey == '' ? $_FILES[$file_field]['type'] : $_FILES[$file_field]['type'][$uploadkey])) {
                 // invalid data mime type found
                 return false;
             }
         }
         //01. we store the file into the file_managed table temporarily, and get the file object
         $file = file_save_upload($uploadkey, array(), NULL);
         //02. we get the file id in the file_managed table, and by using the file id together with the original filename, we create the new filename
         //also, we store the file id into the last_upload_id
         $filename = $file->fid . $_FILES[$file_field]['name'][$uploadkey];
         $this->last_uploaded_id = $file->fid;
         //03. we save the file to be uploaded into the public file directory.
         $file = file_move($file, 'public://' . $filename, FILE_EXISTS_REPLACE);
         //04. set file the status to be permanently and save the file.
         $file->status = FILE_STATUS_PERMANENT;
         variable_set('file_id', $file->fid);
         file_save($file);
         //upload success;
         return true;
     } else {
         // invalid attachment data found
         return false;
     }
 }
开发者ID:zevergreenz,项目名称:Drupal,代码行数:47,代码来源:cvwobase_d7_fileupload.php

示例11: new_file_upload

 public function new_file_upload($file, $type = 'image')
 {
     if (empty($file)) {
         return error(-1, '没有上传内容');
     }
     $limit = 5000;
     $extention = pathinfo($file['name'], PATHINFO_EXTENSION);
     if (empty($type) || $type == 'image') {
         $extentions = array('gif', 'jpg', 'jpeg', 'png');
     }
     if ($type == 'music') {
         $extentions = array('mp3', 'mp4');
     }
     if ($type == 'other') {
         $extentions = array('gif', 'jpg', 'jpeg', 'png', 'mp3', 'mp4', 'doc');
     }
     if (!in_array(strtolower($extention), $extentions)) {
         return error(-1, '不允许上传此类文件');
     }
     if ($limit * 1024 < filesize($file['tmp_name'])) {
         return error(-1, "上传的文件超过大小限制,请上传小于 " . $limit . "k 的文件");
     }
     $result = array();
     $path = '/attachment/';
     $result['path'] = "{$type}/" . date('Y/m/');
     mkdirs(WEB_ROOT . $path . $result['path']);
     do {
         $filename = random(15) . ".{$extention}";
     } while (file_exists(SYSTEM_WEBROOT . $path . $filename));
     $result['path'] .= $filename;
     $filename = WEB_ROOT . $path . $result['path'];
     if (!file_move($file['tmp_name'], $filename)) {
         return error(-1, '保存上传文件失败');
     }
     $result['success'] = true;
     return $result;
 }
开发者ID:jasonhzy,项目名称:bjcms2.3,代码行数:37,代码来源:web.php

示例12: generateValues

 function generateValues($object, $instance, $plugin_definition, $form_display_options)
 {
     $object_field = array();
     static $images = array();
     $settings = $instance->getSettings();
     $min_resolution = empty($settings['min_resolution']) ? '100x100' : $settings['min_resolution'];
     $max_resolution = empty($settings['max_resolution']) ? '600x600' : $settings['max_resolution'];
     $extensions = array_intersect(explode(' ', $settings['file_extensions']), array('png', 'gif', 'jpg', 'jpeg'));
     $extension = array_rand(array_combine($extensions, $extensions));
     // Generate a max of 5 different images.
     if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
         if ($path = $this->generateImage($extension, $min_resolution, $max_resolution)) {
             $account = user_load(1);
             $image = entity_create('file', array());
             $image->setFileUri($path);
             $image->setOwner($account);
             $image->setMimeType('image/' . pathinfo($path, PATHINFO_EXTENSION));
             $image->setFileName(drupal_basename($path));
             $destination_dir = $settings['uri_scheme'] . '://' . $settings['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . '/' . basename($path);
             $file = file_move($image, $destination, FILE_CREATE_DIRECTORY);
             $images[$extension][$min_resolution][$max_resolution][$file->id()] = $file;
         } else {
             return FALSE;
         }
     } else {
         // Select one of the images we've already generated for this field.
         $image_index = array_rand($images[$extension][$min_resolution][$max_resolution]);
         $file = $images[$extension][$min_resolution][$max_resolution][$image_index];
     }
     $object_field['target_id'] = $file->id();
     $object_field['alt'] = DevelGenerateBase::createGreeking(4);
     $object_field['title'] = DevelGenerateBase::createGreeking(4);
     return $object_field;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:36,代码来源:DevelGenerateFieldImage.php

示例13: testHandleFileMunge

 /**
  * Test file munge handling.
  */
 function testHandleFileMunge()
 {
     // Ensure insecure uploads are disabled for this test.
     $this->config('system.file')->set('allow_insecure_uploads', 0)->save();
     $this->image = file_move($this->image, $this->image->getFileUri() . '.foo.' . $this->imageExtension);
     // Reset the hook counters to get rid of the 'move' we just called.
     file_test_reset();
     $extensions = $this->imageExtension;
     $edit = array('files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), 'extensions' => $extensions);
     $munged_filename = $this->image->getFilename();
     $munged_filename = substr($munged_filename, 0, strrpos($munged_filename, '.'));
     $munged_filename .= '_.' . $this->imageExtension;
     $this->drupalPostForm('file-test/upload', $edit, t('Submit'));
     $this->assertResponse(200, 'Received a 200 response for posted test file.');
     $this->assertRaw(t('For security reasons, your upload has been renamed'), 'Found security message.');
     $this->assertRaw(t('File name is @filename', array('@filename' => $munged_filename)), 'File was successfully munged.');
     $this->assertRaw(t('You WIN!'), 'Found the success message.');
     // Check that the correct hooks were called.
     $this->assertFileHooksCalled(array('validate', 'insert'));
     // Ensure we don't munge files if we're allowing any extension.
     // Reset the hook counters.
     file_test_reset();
     $edit = array('files[file_test_upload]' => drupal_realpath($this->image->getFileUri()), 'allow_all_extensions' => TRUE);
     $this->drupalPostForm('file-test/upload', $edit, t('Submit'));
     $this->assertResponse(200, 'Received a 200 response for posted test file.');
     $this->assertNoRaw(t('For security reasons, your upload has been renamed'), 'Found no security message.');
     $this->assertRaw(t('File name is @filename', array('@filename' => $this->image->getFilename())), 'File was not munged when allowing any extension.');
     $this->assertRaw(t('You WIN!'), 'Found the success message.');
     // Check that the correct hooks were called.
     $this->assertFileHooksCalled(array('validate', 'insert'));
 }
开发者ID:318io,项目名称:318-io,代码行数:34,代码来源:SaveUploadTest.php

示例14: file_upload

function file_upload($file, $type = 'image', $name = '', $is_wechat = false)
{
    $harmtype = array('asp', 'php', 'jsp', 'js', 'css', 'php3', 'php4', 'php5', 'ashx', 'aspx', 'exe', 'cgi');
    if (empty($file)) {
        return error(-1, '没有上传内容');
    }
    if (!in_array($type, array('image', 'thumb', 'voice', 'video', 'audio'))) {
        return error(-2, '未知的上传类型');
    }
    global $_W;
    $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
    $ext = strtolower($ext);
    if (!$is_wechat) {
        $setting = $_W['setting']['upload'][$type];
        if (!in_array(strtolower($ext), $setting['extentions']) || in_array(strtolower($ext), $harmtype)) {
            return error(-3, '不允许上传此类文件');
        }
        if (!empty($setting['limit']) && $setting['limit'] * 1024 < filesize($file['tmp_name'])) {
            return error(-4, "上传的文件超过大小限制,请上传小于 {$setting['limit']}k 的文件");
        }
    }
    $result = array();
    if (empty($name) || $name == 'auto') {
        $uniacid = intval($_W['uniacid']);
        $path = "{$type}s/{$uniacid}/" . date('Y/m/');
        mkdirs(ATTACHMENT_ROOT . '/' . $path);
        $filename = file_random_name(ATTACHMENT_ROOT . '/' . $path, $ext);
        $result['path'] = $path . $filename;
    } else {
        mkdirs(dirname(ATTACHMENT_ROOT . '/' . $name));
        if (!strexists($name, $ext)) {
            $name .= '.' . $ext;
        }
        $result['path'] = $name;
    }
    if (!file_move($file['tmp_name'], ATTACHMENT_ROOT . '/' . $result['path'])) {
        return error(-1, '保存上传文件失败');
    }
    $result['success'] = true;
    return $result;
}
开发者ID:ChainBoy,项目名称:wxfx,代码行数:41,代码来源:file.func.php

示例15: generateImage

 public function generateImage($object, $field, $instance, $bundle)
 {
     static $images = array();
     $min_resolution = empty($instance['settings']['min_resolution']) ? '100x100' : $instance['settings']['min_resolution'];
     $max_resolution = empty($instance['settings']['max_resolution']) ? '600x600' : $instance['settings']['max_resolution'];
     $extension = 'jpg';
     if (!isset($images[$extension][$min_resolution][$max_resolution]) || count($images[$extension][$min_resolution][$max_resolution]) <= DEVEL_GENERATE_IMAGE_MAX) {
         if ($tmp_file = drupal_tempnam('temporary://', 'imagefield_')) {
             $destination = $tmp_file . '.' . $extension;
             file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY);
             $min = explode('x', $min_resolution);
             $max = explode('x', $max_resolution);
             $max[0] = $max[0] < $min[0] ? $min[0] : $max[0];
             $max[1] = $max[1] < $min[1] ? $min[1] : $max[1];
             $width = rand((int) $min[0], (int) $max[0]);
             $height = rand((int) $min[1], (int) $max[1]);
             $background_color = isset($this->settings['devel_image_provider_background_color']) ? $this->settings['devel_image_provider_background_color'] : FALSE;
             if ($background_color) {
                 if (preg_match('/^#[a-f0-9]{6}$/i', $background_color)) {
                     // Check for valid hex number
                     $background_color = "/" . str_replace('#', '', check_plain($background_color));
                     // Strip out #
                 } else {
                     $background_color = '';
                 }
             } else {
                 $background_color = '';
             }
             $text_color = isset($this->settings['devel_image_provider_text_color']) ? $this->settings['devel_image_provider_text_color'] : FALSE;
             if ($text_color) {
                 // Check for valid hex number.
                 if (preg_match('/^#[a-f0-9]{6}$/i', $text_color)) {
                     // Strip out # character.
                     $text_color = "/" . str_replace('#', '', check_plain($text_color));
                 } else {
                     $text_color = '';
                 }
             } else {
                 $text_color = '';
             }
             $include_text = isset($this->settings['devel_image_provider_include_text']) ? $this->settings['devel_image_provider_include_text'] : FALSE;
             switch ($include_text) {
                 case 'custom':
                     $custom_text = isset($this->settings['devel_image_provider_custom_text']) ? $this->settings['devel_image_provider_custom_text'] : '';
                     break;
                 case 'random':
                     // Small random text as text size is depending on the image size.
                     $custom_text = trim(substr(devel_create_greeking(mt_rand(1, 3)), 0, 8));
                     break;
                 case 'default':
                 default:
                     $custom_text = '';
                     break;
             }
             if (!empty($custom_text)) {
                 //Replace the spaces with + as per provider specifications
                 $custom_text = "&text=" . str_replace(' ', '+', check_plain($custom_text));
             }
             $url = "{$this->provider_base_url}/" . $width . "x" . $height . '/' . $background_color . '/' . $text_color . '&text=' . $custom_text;
             $method = isset($this->settings['devel_image_provider_get_method']) ? $this->settings['devel_image_provider_get_method'] : 'file_get_contents';
             $path = devel_image_provider_get_file($url, $destination, $method);
             $source = new stdClass();
             $source->uri = $path;
             $source->uid = 1;
             // TODO: randomize? Use case specific.
             $source->filemime = 'image/jpg';
             if (!empty($instance['settings']['file_directory'])) {
                 $instance['settings']['file_directory'] = $instance['settings']['file_directory'] . '/';
             }
             $destination_dir = $field['settings']['uri_scheme'] . '://' . $instance['settings']['file_directory'];
             file_prepare_directory($destination_dir, FILE_CREATE_DIRECTORY);
             $destination = $destination_dir . basename($path);
             $file = file_move($source, $destination, FILE_CREATE_DIRECTORY);
         } else {
             return FALSE;
         }
     } else {
         // Select one of the images we've already generated for this field.
         $file = new stdClass();
         $file->fid = array_rand($images[$extension][$min_resolution][$max_resolution]);
     }
     $object_field['fid'] = $file->fid;
     $object_field['alt'] = devel_create_greeking(4);
     $object_field['title'] = devel_create_greeking(4);
     return $object_field;
 }
开发者ID:kreynen,项目名称:elmsln,代码行数:86,代码来源:DummyImageProvider.class.php


注:本文中的file_move函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。