2014-01-13 32 views
1

執行Dropzone.js並希望在將所有照片添加到dropzone後一次提交。這是在一個wamp服務器中使用PHP kohana運行的。出於某種原因,我無法將照片傳遞到php頁面。在JS帶一次性提交按鈕的Dropzone.js

懸浮窗配置

$(文件)。就緒(函數(){

Dropzone.options.dropzoneForm = { 
      // The camelized version of the ID of the form element 

      paramName: "files", 
      autoProcessQueue: false, 
      uploadMultiple: true, 
      parallelUploads: 100, 
      maxFiles: 100, 
      previewsContainer: ".dropzone-previews", 
      clickable: true, 
      dictDefaultMessage: 'Add files to upload by clicking or droppng them here.', 
      addRemoveLinks: true, 
      acceptedFiles: '.jpg,.pdf,.png,.bmp', 
      dictInvalidFileType: 'This file type is not supported.', 

      // The setting up of the dropzone 
      init: function() { 
       var myDropzone = this; 

       $("button[type=submit]").bind("click", function (e) { 
        e.preventDefault(); 
        e.stopPropagation(); 
        // If the user has selected at least one file, AJAX them over. 
        if (myDropzone.files.length !== 0) { 
         myDropzone.processQueue(); 
        // Else just submit the form and move on. 
        } else { 
         $('#dropzone-form').submit(); 
        } 
       }); 

       this.on("successmultiple", function (files, response) { 
        // After successfully sending the files, submit the form and move on. 
        $('#dropzone-form').submit(); 
       }); 
      } 
     } 
    }); 

形式

<div id="photoContainer"> 

     <form action="/inspections/uploadphotos" method="post" 
     enctype="multipart/form-data" class="dropzone dz-clickable dropzone-previews" id="dropzone-form"> 

     </form> 
      <button type="submit" id="dz" name="dz" value="Submit " /> Submit Photos</button> 
    </div> 

PHP的Kohana

if (!empty($_FILES)) { 
    print_r($_FILES); 

} 

的問題是$ _Files總是空的。任何人都可以提供一些協助配置此?

+3

是否有任何控制檯錯誤?按下瀏覽器中的F12以拉起控制檯。 – mituw16

+1

沒有那裏似乎沒有任何控制檯錯誤。 – user3032973

回答

2

按F12,看到網絡選項卡(預覽),如果$ _FILE設置

如果單擊upload.php的文件u能看到這樣

Array([file] => Array ([name] => migration_3.jpg [type] => image/jpeg [tmp_name] => D:\xampp\tmp\phpA76F.tmp [error] => 0 [size] => 214924)) 
0

使用這樣的檢查(file_exists ($ _FILES ['file'] ['tmp_name'])|| is_uploaded_file($ _ FILES ['file'] ['tmp_name']))

0

當您單擊提交按鈕時,files數組將始終爲空。 Dropzone已經通過Ajax提交文件,以便查看print_r($_FILES);的結果,您需要通過網絡面板使用chrome開發工具(或其他類似的工具)查看結果。

要查看您提交的內容,只需將表單的動作url設置爲所需的函數,並在該函數的某處添加print_r($_FILES);,在chrome中打開開發工具,然後在dropzone中添加文件,然後按照 Steve Bals's回答查看您的結果。