I am having a bit of a problem, i got a snippet of code fomr the php.net site that SHOULD rename a file upon upload, however it dosn’t Take a look and see if you can figure out what i am doing wrong.
[code=php]
$sName = $_FILES[‘img1’][‘name’]; // The name of the file
$sName = str_replace(chr(32), chr(95), $sName);
$ext = split (‘[.]’, $sName); // Split the name from the file
$sFileExt = $ext[count($ext)-1];
$sFileDateName = “../images/cars/”. date(‘dmYs_zw’) . “.” . $sFileExt;
echo $sFileDateName; // this is what i want the files to be named
echo “<br>”;
echo $sName; // this is what they are named at this time
echo “<br>”;
echo $sFileExt; // and this is just the extension
if (preg_match(‘/^(gif|png|jpe?g)$/’,$sFileExt))
{
function my_copy($sName, $sFileDateName)
{
if(is_file($sName)){
return copy($sName, $sFileDateName) && chmod($sFileDateName, 0755);
}
else
{
die(“Sorry cannot copy file: $sName”);
}
}
}
else echo ‘The file you are trying to upload has not got an image extension.;
As you have probably guessed i am trying to name the files with the date, so as to not double up on files. Anyone done this before, or know what i am not doing correctly?
Thanks in advance
Jono