简体   繁体   English

提交表单后拖放要上传的文件

[英]Drag and drop files to be uploaded when the form is submitted

I'm trying to implement drag-and-drop file selection for uploading files synchronously once the form is submitted. 表单提交后,我正在尝试实现拖放文件选择,以便同步上传文件。 I know how regular file uploading works with HTML and PHP. 我知道常规文件上传如何与HTML和PHP一起使用。 And I want to be able to process the files in PHP alongside the ones in the $_FILES array. 而且我希望能够处理PHP中的文件以及$ _FILES数组中的文件。

I've done some research and looked at several plugins but pretty much all of them either upload files once they're dropped into the window or don't use conventional html forms. 我做了一些研究,看了几个插件,但是几乎所有的插件要么在文件被放入窗口后就上传文件,要么不使用传统的html形式。

Any kind of help like ideas, snippets or plugins would be appreciated. 任何想法,摘要或插件之类的帮助将不胜感激。

Thank you! 谢谢!

See below URL i think it is very help full to you. 请参阅下面的URL,我认为这对您有很大帮助。

HTML5 File Uploads with jQuery jQuery的HTML5文件上传

http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/ http://tutorialzine.com/2011/09/html5-file-upload-jquery-php/

jQuery File Upload Plugin With Drag 'n' Drop Support 具有拖放功能的jQuery文件上传插件

http://www.webresourcesdepot.com/jquery-file-upload-plugin-with-drag-n-drop-support/ http://www.webresourcesdepot.com/jquery-file-upload-plugin-with-drag-n-drop-support/

It is impossible to set the files attribute of a file input via JavaScript for security reasons. 出于安全原因,无法设置通过JavaScript输入的文件的文件属性。 See this jsfiddle . 看到这个jsfiddle

So, you cannot select files for a file input via drag and drop, you have to select the files via the file input directly, by clicking on the 'browse files' button. 因此,您不能为通过拖放输入的文件选择文件,而必须通过单击“浏览文件”按钮直接通过文件输入选择文件。

What you can do is to implement an onUpload method for the form, to upload the files when the user clicks the submit button, via AJAX. 您可以做的是为表单实现onUpload方法,当用户单击AJAX时单击“提交”按钮以上传文件。 Then, when the uploads are completed, you submit the form with the other data. 然后,上传完成后,您将表格与其他数据一起提交。

See this fiddle to see how to upload files via AJAX. 请参阅此小提琴,以了解如何通过AJAX上传文件。 The code has the drag and drop processing and converting binary files into BASE64. 该代码具有拖放处理并将二进制文件转换为BASE64。 You will need to create the AJAX bit by posting the data. 您将需要通过发布数据来创建AJAX位。 To check if the files are done, create a function to be called with setInterval , to check if all the uploads completed. 要检查文件是否完成,请创建一个要使用setInterval调用的函数,以检查所有上传是否完成。

Cheers, Apoc 干杯,Apoc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM