PHP上传图像,使用日期时间戳重命名图像


PHP Upload image,rename image with date timestamp

当我在这里为这部分执行此操作时:

$ran = time();
   $ran2 = $ran."."; 
   It is able to set the image name as this: <br> 
   The file has been uploaded as 1379496233.67485,10.jpg <br>
   where by *1379496233 refers to the time();
   But when i do this: <Br>
   $ran = date("g:i:s A D, d/m/y");
   date_default_timezone_set('Singapore');
   $ran2 = $ran.".";  <br>

诸如此类的错误代码

"Warning: move_uploaded_file(images/9:28:13 AM Wed, 18/09/13.1185810_10201356273602710_1568954903_n.jpg) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: Invalid argument in C:'wamp'www'zzzzzzzzzzzzzzzzzzzzzz'v.php on line 35"

&这种情况发生

"Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move 'C:'wamp'tmp'php3E46.tmp' to 'images/9:28:13 AM Wed, 18/09/13.1185810_10201356273602710_1568954903_n.jpg' in C:'wamp'www'zzzzzzzzzzzzzzzzzzzzzz'v.php on line 35"

  <?php
     //This function separates the extension from the rest of the file name and returns it 
     function findexts ($filename) 
     { 
         $filename = strtolower($filename) ; 
         $exts = explode("[/''.]", $filename) ; 
         $n = count($exts)-1; 
         $exts = $exts[$n]; 
         return $exts; 
     } 
     //This applies the function to our file  
     $ext = findexts ($_FILES['uploaded']['name']) ; 
     $ran = time();
     $ran2 = $ran.".";       
     //This assigns the subdirectory you want to save into... make sure it exists!
     $target = "images/";
     //This combines the directory, the random file name, and the extension
     $target = $target . $ran2.$ext; 
     if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
     {
         echo "The file has been uploaded as ".$ran2.$ext;
     } 
     else
     {
         echo "Sorry, there was a problem uploading your file.";
     }
     ?> 

日期时区应为:Asia/Singapore而不是Singapore