2014-09-01 27 views
2

我試圖返回dropzone的成功功能,但它不工作。我需要的路徑和圖像名稱後用圖像上傳頁...如何找回上傳的圖像路徑通過dropzone

我的代碼:

<body> 
    <button id="submit-all">Submit all files</button> 
    <form action="uploads.php" class="dropzone" id="my-dropzone"></form> 

    <script>  
     Dropzone.options.myDropzone = {       
      // Prevents Dropzone from uploading dropped files immediately 
       addRemoveLinks: true, 
       autoProcessQueue: false, 
       maxFilesize:100, 
       parallelUploads:5, 
       maxFiles:5,       
       acceptedFiles: "image/*,.pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.openxmlformats-officedocument.spreadsheetml.template, application/vnd.openxmlformats-officedocument.presentationml.template, application/vnd.openxmlformats-officedocument.presentationml.slideshow, application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.presentationml.slide, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/vnd.openxmlformats-officedocument.wordprocessingml.template, application/vnd.ms-excel.addin.macroEnabled.12, application/vnd.ms-excel.sheet.binary.macroEnabled.12,text/rtf,text/plain,audio/*,video/*,.csv,.doc,.xls,.ppt,application/vnd.ms-powerpoint,.pptx",       
       init: function() { 
        var submitButton = document.querySelector("#submit-all"), 
         myDropzone = this; // closure 

         submitButton.addEventListener("click", function() { 
          myDropzone.processQueue(); // Tell Dropzone to process all queued files 
         });  
       } 
     }; 
    </script>   
</body> 

,並上傳腳本:

$upload_dir = 'uploads'; 
    if (!empty($_FILES)) {           
     $tempFile = $_FILES['file']['tmp_name']; 
     echo $tempFile; 
     // using DIRECTORY_SEPARATOR constant is a good practice, it makes your code portable. 
     $targetPath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $upload_dir . DIRECTORY_SEPARATOR; 
     // Adding timestamp with image's name so that files with same name can be uploaded easily. 
     $mainFile = $targetPath.time().'-'. $_FILES['file']['name']; 

      move_uploaded_file($tempFile,$mainFile); 
    } else { echo 'error: no file'; } 

我需要成功函數返回的路徑上傳的圖片。 謝謝。

回答

0
myDropzone.processQueue(); 
myDropzone.on("success", function(file,responsenew) { 
    // alert(responsenew); 
    var response = jQuery.parseJSON(responsenew); 
    $('#image_update').remove(); 
    if(response.html==undefined || response.html==null) { 

    } 
}); 
+0

使用responsenew從ajax請求返回數據。沿着您的返回數據發送路徑。我用json值返回數據多數民衆贊成爲什麼我用jQuery.parseJSON(responsenew); – 2014-09-01 12:52:23

相關問題