PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
//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";
}
}
I dont see anything in your code that relates to a database, but you can use the php function file_exists() to check if the file exists on the file system.