public function FileSystem::moveUploadedFile in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/File/FileSystem.php \Drupal\Core\File\FileSystem::moveUploadedFile()
Moves an uploaded file to a new location.
PHP's move_uploaded_file() does not properly support streams if open_basedir is enabled, so this function fills that gap.
Compatibility: normal paths and stream wrappers.
Parameters
string $filename: The filename of the uploaded file.
string $uri: A string containing the destination URI of the file.
Return value
bool TRUE on success, or FALSE on failure.
Overrides FileSystemInterface::moveUploadedFile
See also
https://www.drupal.org/node/515192
File
- core/
lib/ Drupal/ Core/ File/ FileSystem.php, line 75
Class
- FileSystem
- Provides helpers to operate on files and stream wrappers.
Namespace
Drupal\Core\FileCode
public function moveUploadedFile($filename, $uri) {
$result = @move_uploaded_file($filename, $uri);
// PHP's move_uploaded_file() does not properly support streams if
// open_basedir is enabled so if the move failed, try finding a real path
// and retry the move operation.
if (!$result) {
if ($realpath = $this
->realpath($uri)) {
$result = move_uploaded_file($filename, $realpath);
}
else {
$result = move_uploaded_file($filename, $uri);
}
}
return $result;
}