function FileSystemInterface::move
Same name in other branches
- 9 core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::move()
- 8.9.x core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::move()
- 11.x core/lib/Drupal/Core/File/FileSystemInterface.php \Drupal\Core\File\FileSystemInterface::move()
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().
- Checks if $source and $destination are valid and readable/writable.
- Checks that $source is not equal to $destination; if they are an error is reported.
- If file already exists in $destination either the call will error out, replace the file or rename the file based on the $fileExists parameter.
- Works around a PHP bug where rename() does not properly support streams if safe_mode or open_basedir are enabled.
Parameters
string $source: A string specifying the filepath or URI of the source file.
string $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 (public://) will be used.
\Drupal\Core\File\FileExists|int $fileExists: Replace behavior when the destination file already exists.
Return value
string The path to the new file.
Throws
\Drupal\Core\File\Exception\FileException Implementation may throw FileException or its subtype on failure.
\ValueError Thrown if $fileExists is a legacy int and not a valid value.
See also
https://bugs.php.net/bug.php?id=60456
File
-
core/
lib/ Drupal/ Core/ File/ FileSystemInterface.php, line 367
Class
- FileSystemInterface
- Provides an interface for helpers that operate on files and stream wrappers.
Namespace
Drupal\Core\FileCode
public function move($source, $destination, $fileExists = FileExists::Rename);
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.