From 164371f70f9f9e7aa6eafaf9ac2222ac14c4233e Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 29 Dec 2005 01:46:32 +0000 Subject: [PATCH] Fix extension handling. git-svn-id: https://develop.svn.wordpress.org/trunk@3377 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/functions-post.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index ee9c959392..74a8ea065b 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -904,9 +904,19 @@ function wp_upload_bits($name, $type, $bits) { $number = ''; $filename = $name; - while ( file_exists($upload['path'] . "/$filename") ) - $filename = str_replace("$number.$ext", ++$number . ".$ext", $filename); - + $path_parts = pathinfo($filename); + $ext = $path_parts['extension']; + if ( empty($ext) ) + $ext = ''; + else + $ext = ".$ext"; + while ( file_exists($upload['path'] . "/$filename") ) { + if ( '' == "$number$ext" ) + $filename = $filename . ++$number . $ext; + else + $filename = str_replace("$number$ext", ++$number . $ext, $filename); + } + $new_file = $upload['path'] . "/$filename"; $ifp = @ fopen($new_file, 'wb'); if ( ! $ifp )