file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXISTS_RENAME)
Moves a file to a new location without database changes or hook invocation.
This is a powerful function that in many ways performs like an advanced version of rename().
$source: A string specifying the filepath or URI of the source file.
$destination: A URI containing the destination that $source should be moved to. The URI may be a bare filepath (without a scheme) and in that case the default scheme (file://) will be used. If this value is omitted, Drupal's default files scheme will be used, usually "public://".
$replace: Replace behavior when the destination file already exists:
The path to the new file, or FALSE in the event of an error.
https://bugs.php.net/bug.php?id=60456
function file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXISTS_RENAME) { if (!file_unmanaged_prepare($source, $destination, $replace)) { return FALSE; } // Ensure compatibility with Windows. // @see drupal_unlink() if ((substr(PHP_OS, 0, 3) == 'WIN') && (!file_stream_wrapper_valid_scheme(file_uri_scheme($source)))) { chmod($source, 0600); } // Attempt to resolve the URIs. This is necessary in certain configurations // (see above) and can also permit fast moves across local schemes. $real_source = drupal_realpath($source) ? : $source; $real_destination = drupal_realpath($destination) ? : $destination; // Perform the move operation. if (!@rename($real_source, $real_destination)) { // Fall back to slow copy and unlink procedure. This is necessary for // renames across schemes that are not local, or where rename() has not been // implemented. It's not necessary to use drupal_unlink() as the Windows // issue has already been resolved above. if (!@copy($real_source, $real_destination) || !@unlink($real_source)) { \Drupal::logger('file')->error('The specified file %file could not be moved to %destination.', array('%file' => $source, '%destination' => $destination)); return FALSE; } } // Set the permissions on the new file. drupal_chmod($destination); return $destination; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!includes!file.inc/function/file_unmanaged_move/8.1.x