如何将上传的文件从Dropzone传递到操作URL?

时间:2014-04-25 16:32:11

标签: php jquery forms dropzone.js

我有一个构建为自定义Typo3(PHP)扩展的表单。在附加Dropzone之前,表单正常工作 - 如果我填写信息,上传文件并提交表单,则会执行正确的操作(在这种情况下,这意味着我会收到一封包含所有信息和上传文件的电子邮件)作为附件)。

如果我按照本文Combine normal form with Dropzone中的说明操作,我可以将文件拖放到我的表单上,并且可以看到文件预览。当我点击"提交"时,我收到Typo3 / PHP错误:

   :saveUserFiles() must be of the type array, null given

这看起来像Dropzone将文件传递到后端的方式有问题 - 有什么方法可以让我看看Dropzone传递的提交内容是什么?

这是我的Dropzone选项,几乎没有改变上面常见问题解答页面上的建议:

 Dropzone.options.general = {
                paramName: "file", // The name that will be used to transfer the file

                autoProcessQueue: false,
                uploadMultiple: true,
                parallelUploads: 100,
                maxFiles: 100,
                addRemoveLinks: true,

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

                    // First change the button to actually tell Dropzone to process the queue.
                    this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
                        // Make sure that the form isn't actually being sent.
                        e.preventDefault();
                        e.stopPropagation();
                        myDropzone.processQueue();
                    });

                    // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
                    // of the sending event because uploadMultiple is set to true.
                    this.on("sendingmultiple", function() {
                        console.log("sending multiple");
                    });
                    this.on("successmultiple", function(files, response) {
                        console.log("success multiple");
                    });
                    this.on("errormultiple", function(files, response) {
                        console.log("error multiple");
                    });
                }
            };

-

更新,以回复评论:

"正常上传"输入看起来像这样:

<input type="file" name="tx_applicationformgeneral[form][files][]" />

我尝试将文件输入的名称放入Dropzone选项中,如下所示:

paramName: "tx_applicationformgeneral[form][files][]",

但是得到了同样的错误。

这里是整个表单结构(简化 - 它是一个很长的表单):

 <form enctype="multipart/form-data" method="post" name="form" class="dropzone dz-clickable" id="general" action="index.php?id=328">


<fieldset>

    <legend>Some input</legend>


    <ul class="inline-textbox">
        <li>

    <input type="text" id="first_name" name="tx_applicationformgeneral[form][firstname]" value="" placeholder="Name *">
        </li>
        <li>

    </ul>
</fieldset>

<fieldset>

    <legend>File upload</legend>

    <div class="dropzone-previews">

    </div>

</fieldset>


<input class="button" type="submit" name="tx_applicationformgeneral[mySubmit]" value="Submit">

 </form>

更新2

按照评论中的建议查看POST数据后,我现在可以报告发生的情况是,当表单是&#34; Dropzoned&#34;表单为文件上传输入发送NO数据。 &#34;非Dropzoned&#34;如果文件上传为空,则表单发送此数据块:

 ------WebKitFormBoundarySq0AkJrSAe1kmAOu
 Content-Disposition: form-data; name="tx_applicationformgeneral[form][files][]";      filename=""
 Content-Type: application/octet-stream

如果有文件,那就是这个:

 ------WebKitFormBoundaryrEmFA8jYcHY56WAB
 Content-Disposition: form-data; name="tx_applicationformgeneral[form][files][]";      filename="DSC01413_01.JPG"
 Content-Type: image/jpeg

一旦我将表单初始化为Dropzone,POST数据中就没有与此信息相对应的内容。

0 个答案:

没有答案