php jquery图片上传

i have a script that uploads an image into a folder instead of saving it as a blob..

<?php
mysql_connect('localhost','root','')or die(mysql_error());
mysql_select_db('db_tourism')or die(mysql_error());
//$newname='baro.jpg';
//dir:[../../]
$uploaddir = '../../images/municipality/';
$cc=$uploaddir.$fileName;
$fileName = $_FILES['uploadfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$ext = end(explode('.', $fileName));
$newname=$fileName;//.'.'.$ext;

$file = $uploaddir .$newname; //basename($_FILES['uploadfile']['name']); 

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 

 // echo "<script>alert('success:$fileName');</script>"; 

mysql_query("INSERT INTO `_temp-image` ( `id` , `File_name` , `path` ) 
VALUES (
NULL , '$fileName', '$file'
);");

 echo "success";
} 
else {
    echo "error";
}
?>

and here is the jquery

    var btnUpload=$('#uploada');
    //var btnUploadTxt=$('#uploada').attr('value');
    var status=$('#status');
    new AjaxUpload(btnUpload, {
        action: 'upload-file.php',
        name: 'uploadfile',
        onSubmit: function(file, ext){
             if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                // extension is not allowed 
                btnUpload.val('Only JPG, PNG or GIF files are   allowed');
                return false;
            }
            btnUpload.val('Uploading...');
        },
        onComplete: function(file, response){
            //On completion clear the status
            btnUpload.val('Upload Picture');
            //Add uploaded file to list
            if(response==="success"){
                $('<li class="uplod" uid="_temp-image" title="click     to remove ['+file+']" id="'+file+'  "><span  id=" '+file+' " style="font-  family:calibri;font-size:10px;" >'+file+' [UPLOADED]</span></li>').appendTo('#uploaded');/  *.html('<img src="../uploaded_image/'+file+'" alt="" />'+file)*///.addClass('success');
            } else{
                $('<li></li>').appendTo('#uploaded').text(fi    le).addClass('error');
            }
        }
    });

it works fine i can add and delete picture... BUT my problem is handling DUPLICATE files... how to error trap if that kind of image is already uploaded??

Generate CRC checksum, MD5 or other hash type for image binary data and store that hash in database.

After upload - check new image checksum/hash and compare it with that stored in database.

Use md5_file function.

$md5hash = md5_file(string $filename);

Here is more: http://www.php.net/manual/en/function.md5-file.php