Dropzone.js与一次性提交按钮

实现Dropzone.js并希望在将所有照片添加到dropzone后进行一次性提交。 现在,这是在一个wamp服务器内运行PHP kohana。 由于某种原因,我无法将照片传递到php页面。

在js上的Dropzone配置

$(document).ready(function(){

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(); }); } } }); 

形成

  

PHP Kohana

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

问题是$ _Files总是空的。 有人可以提供一些配置吗?

按F12并看到网络选项卡(预览),然后单击upload.php文件,你可以看到这样的

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

使用这样的东西来检查是否设置了$ _FILE

if(file_exists($ _ FILES [‘file’] [‘tmp_name’])|| is_uploaded_file($ _ FILES [‘file’] [‘tmp_name’]))

单击“提交”按钮时,files数组将始终为空。 Dropzone已经通过Ajax提交文件,以便查看print_r($_FILES);的结果print_r($_FILES); 您需要使用chrome dev工具(或其他类似工具)通过网络面板查看结果。

要查看您提交的内容,只需将表单的操作URL设置为所需的function,然后添加print_r($_FILES); 在该function的某个地方,打开chrome中的开发工具,然后在dropzone中添加文件,并按照Steve Bals的回答中的步骤查看结果。