2014-01-13 26 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回答查看您的结果。