Hi All, I have an image upload that works for my requirements -
But what I am unable to figure out is how to rename the image to the datatime stamp and to keep the file extension
.jpg / .png / .gif / .jpeg etc
I have a variable $datetime
$datetime = date('l jS F Y h:i:s');
here is the code that I am trying to work with -
Any help with be much appreciated -
////////////////////////////////////////////////////////////////////////////////////////////////////////////
$img1 = $_FILES['jan_image']['name'];
//Add a security check, to make sure only allowed files are uploaded
$ext=explode('.',$img1);//explode the image name into an array to get the extension
$allowed_exts=array('jpg','jpeg','png','bmp','gif');// allowed extensions
if(in_array(strtolower($ext[1]), $allowed_exts)){//file type is allowed!
//destination
$dest="members/$securecode/$sname/images/igal/".$img1;
//temp image name
$val= move_uploaded_file($_FILES['jan_image']['tmp_name'], $dest);
chmod($dest, 0644);//make sure you have permissions for the file
if($val)
{ //update database and rename
//rename image to datetime stamp
rename($dest, 'members/'.$securecode.'/'.$sname.'/images/igal/jan.jpg');
//set $dest to the new file name so the database entry is correct
$dest="members/".$securecode."/".$sname."/images/igal/jan.jpg";
mysql_query("update tbl set igimg1='$dest' where id=$lastid");
}
}