php jquery image upload
<p>i have a script that uploads an image into a folder instead of saving it as a blob.. </p>

<pre><code>&lt;?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 "&lt;script&gt;alert('success:$fileName');&lt;/script&gt;"; 

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

 echo "success";
} 
else {
    echo "error";
}
?&gt;
</code></pre>

<p>and here is the jquery</p>

<pre><code>    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 &amp;&amp; /^(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"){
                $('&lt;li class="uplod" uid="_temp-image" title="click     to remove ['+file+']" id="'+file+'  "&gt;&lt;span  id=" '+file+' " style="font-  family:calibri;font-size:10px;" &gt;'+file+' [UPLOADED]&lt;/span&gt;&lt;/li&gt;').appendTo('#uploaded');/  *.html('&lt;img src="../uploaded_image/'+file+'" alt="" /&gt;'+file)*///.addClass('success');
            } else{
                $('&lt;li&gt;&lt;/li&gt;').appendTo('#uploaded').text(fi    le).addClass('error');
            }
        }
    });
</code></pre>

<p>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?? </p>
