file_move($source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
drupal/includes/file.inc, line 542
Move a file to a new location and update the file's database entry.
Moving a file is performed by copying the file to the new location and then deleting the original.
@see file_unmanaged_move() @see hook_file_move()
$source A file object.
$destination A string containing the directory $source should be copied to. If this value is omitted, Drupal's 'files' directory will be used.
$replace Replace behavior when the destination file already exists:
Resulting file object for success, or FALSE in the event of an error.
| Name | Description |
|---|---|
| File interface | Common file handling functions. |
function file_move($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
$source = (object)$source;
if ($filepath = file_unmanaged_move($source->filepath, $destination, $replace)) {
$file = clone $source;
$file->filename = basename($filepath);
$file->filepath = $filepath;
if ($file = file_save($file)) {
// Inform modules that the file has been moved.
module_invoke_all('file_move', $file, $source);
return $file;
}
drupal_set_message(t('The removal of the original file %file has failed.', array('%file' => $source->filepath)), 'error');
}
return FALSE;
}