function file_create_filename in Drupal 4
Same name and namespace in other branches
- 8 core/includes/file.inc \file_create_filename()
- 5 includes/file.inc \file_create_filename()
- 6 includes/file.inc \file_create_filename()
- 7 includes/file.inc \file_create_filename()
Create a full file path from a directory and filename. If a file with the specified name already exists, an alternative will be used.
Parameters
$basename string filename:
$directory string directory:
Related topics
4 calls to file_create_filename()
- theme_upload_attachments in modules/
upload.module - Displays file attachments in table
- upload_menu in modules/
upload.module - Implementation of hook_menu().
- upload_nodeapi in modules/
upload.module - Implementation of hook_nodeapi().
- _upload_form in modules/
upload.module
File
- includes/
file.inc, line 437 - API for handling file uploads and server file management.
Code
function file_create_filename($basename, $directory) {
$dest = $directory . '/' . $basename;
if (file_exists($dest)) {
// Destination file already exists, generate an alternative.
if ($pos = strrpos($basename, '.')) {
$name = substr($basename, 0, $pos);
$ext = substr($basename, $pos);
}
else {
$name = $basename;
}
$counter = 0;
do {
$dest = $directory . '/' . $name . '_' . $counter++ . $ext;
} while (file_exists($dest));
}
return $dest;
}