function file_move


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 file_move(stdClass $source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
cle7 file_move(stdClass $source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
elmsmedia7 file_move(stdClass $source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
icor7 file_move(stdClass $source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
meedjum_blog7 file_move(stdClass $source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
mooc7 file_move(stdClass $source, $destination = NULL, $replace = FILE_EXISTS_RENAME)

Moves 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.

  • Checks if $source and $destination are valid and readable/writable.
  • Performs a file move if $source is not equal to $destination.
  • If file already exists in $destination either the call will error out, replace the file or rename the file based on the $replace parameter.
  • Adds the new file to the files database.


$source: A file object.

$destination: A string containing the destination that $source should be moved to. This must be a stream wrapper URI.

$replace: Replace behavior when the destination file already exists:

  • FILE_EXISTS_REPLACE - Replace the existing file. If a managed file with the destination name exists then its database entry will be updated and file_delete() called on the source file after hook_file_move is called. If no database entry is found then the source files record will be updated.
  • FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique.
  • FILE_EXISTS_ERROR - Do nothing and return FALSE.

Return value

Resulting file object for success, or FALSE in the event of an error.

See also



Related topics

19 calls to file_move()
BaconmockupProvider::generateImage in sites/all/modules/ulmus/devel_image_provider/plugins/devel_image_provider/provider/BaconmockupProvider.class.php
Image generation handler.
DummyImageProvider::generateImage in sites/all/modules/ulmus/devel_image_provider/plugins/devel_image_provider/provider/DummyImageProvider.class.php
Image generation handler.
filefield_paths_filefield_paths_process_file in sites/all/modules/ulmus/filefield_paths/modules/
Implements hook_filefield_paths_process_file().
file_entity_add_upload_submit in sites/all/modules/ulmus/file_entity/
Submit handler for the add file form.
file_entity_edit_submit in sites/all/modules/ulmus/file_entity/
Form submission handler for the 'Save' button for file_entity_edit().

... See full list

1 string reference to 'file_move'
file_entity_hook_info_alter in sites/all/modules/ulmus/file_entity/file_entity.module
Implements hook_hook_info_alter().


includes/, line 1035
API for handling file uploads and server file management.


function file_move(stdClass $source, $destination = NULL, $replace = FILE_EXISTS_RENAME) {
  if (!file_valid_uri($destination)) {
    if (($realpath = drupal_realpath($source->uri)) !== FALSE) {
      watchdog('file', 'File %file (%realpath) could not be moved, because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->uri, '%realpath' => $realpath, '%destination' => $destination));
    else {
      watchdog('file', 'File %file could not be moved, because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', array('%file' => $source->uri, '%destination' => $destination));
    drupal_set_message(t('The specified file %file could not be moved, because the destination is invalid. More information is available in the system log.', array('%file' => $source->uri)), 'error');
    return FALSE;

  if ($uri = file_unmanaged_move($source->uri, $destination, $replace)) {
    $delete_source = FALSE;

    $file = clone $source;
    $file->uri = $uri;
    // If we are replacing an existing file re-use its database record.
    if ($replace == FILE_EXISTS_REPLACE) {
      $existing_files = file_load_multiple(array(), array('uri' => $uri));
      if (count($existing_files)) {
        $existing = reset($existing_files);
        $delete_source = TRUE;
        $file->fid = $existing->fid;
    // If we are renaming around an existing file (rather than a directory),
    // use its basename for the filename.
    elseif ($replace == FILE_EXISTS_RENAME && is_file($destination)) {
      $file->filename = drupal_basename($destination);

    $file = file_save($file);

    // Inform modules that the file has been moved.
    module_invoke_all('file_move', $file, $source);

    if ($delete_source) {
      // Try a soft delete to remove original if it's not in use elsewhere.

    return $file;
  return FALSE;



Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/ in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/
The website encountered an unexpected error. Please try again later.