I'm back with another uploader question. How can I overwrite the image that is already in the users directory? The user can have either gif or jpg image, but are only allowed one image. So if they first uploaded a jpg, then a gif later on, it shows both the images. How can I get the different file formats to overwrite eachother?
If the code is in the uploader, here's the upoloader script
If the code is in the uploader, here's the upoloader script
PHP Code:
$new_home_for_image="../users/$username/";
if($HTTP_POST_FILES['photo']['tmp_name'])
{
$path=$new_home_for_image.$HTTP_POST_FILES['photo']['name'];
if(!copy($HTTP_POST_FILES['photo']['tmp_name'],$path))
{
copy("nophoto.gif","../users/$username/nophoto.gif");
}else{
$type=array('','.gif','.jpg');
$bits=getimagesize($path);
$newname=$username.$type[$bits[2]];
if(rename($path,str_replace($HTTP_POST_FILES['photo']['name'],$newname,$path)))
{
echo "";
}
}
}
Comment