Image filename check
Posted: Thu Apr 15, 2010 3:50 pm
Hi,
I have the below code in my script and I would like to add a check to this code so that when a user tries to upload an image, the system will check that the image name is unique from all other image names in the database. If there is an image with the same name in the database an error msg will show up telling the user to change the image name or something.
Any help please?
I have the below code in my script and I would like to add a check to this code so that when a user tries to upload an image, the system will check that the image name is unique from all other image names in the database. If there is an image with the same name in the database an error msg will show up telling the user to change the image name or something.
Any help please?
Code: Select all
//checking if an image was uploaded
if (strlen($image['name']) > 0)
{
//checking if image is JPG
if ($image['type'] == "image/jpeg" || $image['type'] == "image/pjpeg")
{
$filename = $image['name'];
//uploading the file
move_uploaded_file($image['tmp_name'], "images/users/" . $image['name']);
//remove old image
if (strlen($currentimage) > 0)
unlink("images/users/" . $currentimage);
}
else
{
$message = "Only .jpg images are allowed to be uploaded";
}
}