unique filename fixes from tellyworth. fixes #5482

git-svn-id: http://svn.automattic.com/wordpress/trunk@6401 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-12-18 03:32:43 +00:00
parent 8a556e5e48
commit 83ccac4372
2 changed files with 8 additions and 7 deletions

View File

@ -147,7 +147,7 @@ function wp_handle_upload( &$file, $overrides = false ) {
if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
return $upload_error_handler( $file, $uploads['error'] );
$filename = wp_unique_filename( $uploads['path'], $file['name'], $ext, $unique_filename_callback );
$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
// Move the file to the uploads dir
$new_file = $uploads['path'] . "/$filename";

View File

@ -1064,7 +1064,12 @@ function wp_upload_dir( $time = NULL ) {
}
// return a filename that is sanitized and unique for the given directory
function wp_unique_filename( $dir, $name, $ext, $unique_filename_callback = NULL ) {
function wp_unique_filename( $dir, $filename, $unique_filename_callback = NULL ) {
// separate the filename into a name and extension
$info = pathinfo($filename);
$ext = $info['extension'];
$name = basename($filename, ".{$ext}");
// Increment the file number until we have a unique file to save in $dir. Use $override['unique_filename_callback'] if supplied.
if ( $unique_filename_callback && function_exists( $unique_filename_callback ) ) {
@ -1104,11 +1109,7 @@ function wp_upload_bits( $name, $deprecated, $bits, $time = NULL ) {
if ( $upload['error'] !== false )
return $upload;
$filename = $name;
$path_parts = pathinfo( $filename );
$ext = $path_parts['extension'];
$filename = wp_unique_filename( $upload['path'], $path_parts['basename'], $ext );
$filename = wp_unique_filename( $upload['path'], $name );
$new_file = $upload['path'] . "/$filename";
if ( ! wp_mkdir_p( dirname( $new_file ) ) ) {