file_destination

file_destination($destination, $replace)

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.

Return value

The destination filepath, or FALSE if the file already exists and FILE_EXISTS_ERROR is specified.

Related topics

File interface
Common file handling functions.

File

core/includes/file.inc, line 581
API for handling file uploads and server file management.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.