dropzone.js sends empty $_FILES

六眼飞鱼酱① 提交于 2020-07-22 05:14:11

问题


I try to use dropzone.js to make a drag-and-drop file upload area and I'm getting really desperate here. I have this simplest script:

<?php
  print_r($_FILES);
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
        <meta charset="utf-8">
    </head>
    <body>
        <form action="/" method="POST" enctype="multipart/form-data" class="dropzone">
            <input name="file" type="file" />
            <input type="submit" name="submit" value="Submit" />
        </form>
        <script type='text/javascript' src="dropzone.js"></script>
    </body>
</html>

When I manually select the file using the file input button, I get this result:

Array ( [file] => Array ( [name] => test.txt [type] => text/plain [tmp_name] => C:\wamp\tmp\php4DFF.tmp [error] => 0 [size] => 247 ) )

However, when I use dropzone drag-and-drop, the file appears as uploaded, but after submitting I get this:

Array ( [file] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )

Also known as UPLOAD_ERR_NO_FILE Value: 4; No file was uploaded.

Am I missing something here?

I tried to play with settings like autoProcessQueue: false, autoDiscover: false, automatic form submission, different scripts, different servers (apache/nginx), but absolutely nothing seems to work for me. There got to be some stupid thing that I'm just overseeing right now.

I use dropzone.js v4.0.1 but I tried older versions as well.


回答1:


You should not be submitting (hitting the submit button) with drop zone, it works asynchronously so once you drop the file in, it is hitting your php upload script without a need to do anything else. Once you hit submit it will be a second time, you are resubmitting the form and it will show up empty.

You should probably have your php on a separate page, as well, instead of submitting to itself. You will not be able to view this post in a browser after you submit it because it is ajax and async, but you can use chrome's dev tools to view the post at least.



来源:https://stackoverflow.com/questions/29147180/dropzone-js-sends-empty-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!