Dropzone.js与一次性提交按钮

时间:2014-01-13 18:29:03

标签: javascript php jquery dropzone.js

实施Dropzone.js并希望在将所有照片添加到dropzone后进行一次性提交。现在正在使用PHP kohana在wamp服务器中运行。出于某种原因,我无法将照片传递到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();
                });
            }
        }
   });

表格

 <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 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

使用类似的东西来检查是否设置了$ _FILE

if(file_exists($ _ FILES [&#39; file&#39;] [&#39; tmp_name&#39;])|| is_uploaded_file($ _ FILES [&#39; file&#39;] [&#39 ; tmp_name的值&#39;]))

答案 2 :(得分:0)

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

要查看您提交的内容,只需将表单的操作网址设置为您想要的功能,然后在该功能的某处添加print_r($_FILES);,在Chrome中打开开发工具,然后在dropzone中添加文件,然后关注中的步骤 Steve Bals's回答看到你的结果。