Well, if all the images are stored in the same directory, you can do something like this:
// The form has been uploaded
if($_POST['upload'])
{
$upfile_name = $_FILES['upfile']['name'];
$dir = "images/";
// if a file with that name already exists on server
if (file_exists("$dir$upfile_name"))
{
echo "Sorry, that filename has already been used!";
}
}
You would obviously still have to copy the file over still and check for empty files, but that should do the trick for duplicate filenames. And, as a bonus, there is no SQL querying involved which speeds up the script.