简体   繁体   English

使用Ajax上传多文件以及提交表单

[英]Multi file upload with ajax along with a form submit

I need to design a form with several text field and several file to be uploaded along with the form. 我需要设计一个带有多个文本字段和几个文件的表格,并将其与表格一起上传。 I would like to use ajax to to submit it, and i was thinking about using a jquery plugin to show a progress bar.(I am using php server side) 我想使用ajax提交它,并且我正在考虑使用一个jQuery插件来显示进度栏。(我正在使用php服务器端)

The problem is that if i use something like that, the upload start asyncronously, but i want to really upload the files only when the whole form is validated and submitted. 问题是,如果我使用类似的方法,上传将异步开始,但是我只想在验证并提交整个表单后才真正上传文件。

Is there a way to pre-upload the files showing the progress bars, but to really save them on form submit? 有没有一种方法可以预上传显示进度条的文件,但是真的可以将它们保存在表单提交中? What happens if the user pre-upload the files then closes the form? 如果用户预先上传文件然后关闭表单,会发生什么?

The following two statements are incongruous: 以下两个语句不一致:

"i want to really upload the files only when the whole form is validated and submitted." “我只想在验证并提交整个表单后才真正上传文件。”

"...pre-upload the files showing the progress bars, but to really save them on form submit" “ ...预上传显示进度条的文件,但实际上将其保存在表单提交中”

If you want to upload the files in the background but only save them once the form is submitted, do something like this: 如果您想在后台上传文件,但仅在提交表单后保存它们,请执行以下操作:

  • Upload in the background to a "holding" directory 在后台上传到“保存”目录
  • When the user submits the form, move the files from the "holding" directory into the real storage directory 用户提交表单时,将文件从“持有”目录移至实际存储目录
  • Periodically delete any files in the "holding" director that are older than X hours 定期删除“保留”控制器中早于X小时的所有文件

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

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