PHP Upload image,rename image with date timestamp
When i do this for this part here:
$ran = time();
$ran2 = $ran.".";
It is able to set the image name as this:
The file has been uploaded as 1379496233.67485,10.jpg
where by *1379496233 refers to the time();
But when i do this:
$ran = date("g:i:s A D, d/m/y"); date_default_timezone_set('Singapore');
$ran2 = $ran.".";
Error code such as this "Warning: move_uploaded_file(images/9:28:13 AM
Wed, 18/09/13.1185810_10201356273602710_1568954903_n.jpg)
[function.move-uploaded-file]: failed to open stream: Invalid argument in
C:\wamp\www\zzzzzzzzzzzzzzzzzzzzzz\v.php on line 35" & this occurs
"Warning: move_uploaded_file() [function.move-uploaded-file]: 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.";
}
?>
No comments:
Post a Comment