wp_unique_filename [ WordPress Function ]
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Get a filename that is sanitized and unique for the given directory.
If the filename is not unique, then a number will be added to the filename before the extension, and will continue adding numbers until the filename is unique.
The callback is passed three parameters, the first one is the directory, the second is the filename, and the third is the extension.
Source
<?php
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) {
// sanitize the file name before we begin processing
$filename = sanitize_file_name($filename);
// separate the filename into a name and extension
$info = pathinfo($filename);
$ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
$name = basename($filename, $ext);
// edge case: if file is named '.ext', treat as an empty name
if ( $name === $ext )
$name = '';
// Increment the file number until we have a unique file to save in $dir. Use callback if supplied.
if ( $unique_filename_callback && is_callable( $unique_filename_callback ) ) {
$filename = call_user_func( $unique_filename_callback, $dir, $name, $ext );
} else {
$number = '';
// change '.ext' to lower case
if ( $ext && strtolower($ext) != $ext ) {
$ext2 = strtolower($ext);
$filename2 = preg_replace( '|' . preg_quote($ext) . '$|', $ext2, $filename );
// check for both lower and upper case extension or image sub-sizes may be overwritten
while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
$new_number = $number + 1;
$filename = str_replace( "$number$ext", "$new_number$ext", $filename );
$filename2 = str_replace( "$number$ext2", "$new_number$ext2", $filename2 );
$number = $new_number;
}
return $filename2;
}
while ( file_exists( $dir . "/$filename" ) ) {
if ( '' == "$number$ext" )
$filename = $filename . ++$number . $ext;
else
$filename = str_replace( "$number$ext", ++$number . $ext, $filename );
}
}
return $filename;
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp unique filename « WordPress Codex
Function Reference/wp unique filename. Description. This function can be used before saving a file to make sure it has a filename that is sanitized and unique ...
codex.wordpress.org - WordPress › WordPress Ideas — Add a filter to wp_unique_filename
function wp_unique_filename( $dir, $filename, $unique_filename_callback = null ) ... There is no way to use custom wp_unique_filename generator @ function ...
wordpress.org - wp_unique_filename
Function and Method Cross Reference. wp_unique_filename(). Defined at: /wp- includes/functions.php -> line 1496. Referenced 6 times: ...
phpxref.ftwr.co.uk - wp_unique_filename (WordPress Function) - WPSeek.com
WordPress lookup for wp_unique_filename, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com