function file_destination in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/includes/file.inc \file_destination()
Determines the destination path for a file.
Parameters
$destination: A string specifying the desired final URI or filepath.
$replace: Replace behavior when the destination file already exists.
- FILE_EXISTS_REPLACE - Replace the existing file.
- FILE_EXISTS_RENAME - Append _{incrementing number} until the filename is unique.
- FILE_EXISTS_ERROR - Do nothing and return FALSE.
Return value
The destination filepath, or FALSE if the file already exists and FILE_EXISTS_ERROR is specified.
Related topics
4 calls to file_destination()
- DirectoryTest::testFileDestination in core/
modules/ system/ src/ Tests/ File/ DirectoryTest.php - This will test the filepath for a destination based on passed flags and whether or not the file exists.
- EntityFile::writeFile in core/
modules/ file/ src/ Plugin/ migrate/ destination/ EntityFile.php - Tries to move or copy a file.
- file_save_upload in core/
modules/ file/ file.module - Saves file uploads to a new location.
- file_unmanaged_copy in core/
includes/ file.inc - Copies a file to a new location without invoking the file API.
File
- core/
includes/ file.inc, line 547 - API for handling file uploads and server file management.
Code
function file_destination($destination, $replace) {
if (file_exists($destination)) {
switch ($replace) {
case FILE_EXISTS_REPLACE:
// Do nothing here, we want to overwrite the existing file.
break;
case FILE_EXISTS_RENAME:
$basename = drupal_basename($destination);
$directory = drupal_dirname($destination);
$destination = file_create_filename($basename, $directory);
break;
case FILE_EXISTS_ERROR:
// Error reporting handled by calling function.
return FALSE;
}
}
return $destination;
}