Ajax文件上传获取重复图像

I have downloaded php-ajax multiple upload file from Multiple File Drag and Drop Upload

i have setup this code in my local xampp server. This code is working fine when i am uploading original image with no changes but when i rename the file name in first time it works fine second time it is not working. File uploads 2 times in every images. Third time it uploads 3 times in local server simultaneously.

Old Code:

<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
    if(move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES['file']['name'])){
        echo($_POST['index']);
    }
    exit;
}
?>

My Changes Code:

<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
    $photo=time().rand(1,1000).'.'.substr(strrchr($_FILES['file']['name'],'.'),1);
    if(move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$photo)){
        echo($_POST['index']);
    }
    exit;
}
?>

Please help me and tell me how to upload rename images without page refresh?

  1. Use the tempnam() to get the unique filename.
  2. Clean the form content in form.submit() event =)