如何在 HTML 表单上上传多个文件

问题描述 投票:0回答:2

我本以为在互联网上找到答案会非常容易,但显然不是。

在 HTML 页面上,我希望允许用户选择多个文件并将它们上传到我的服务器。具体上下文是用户需要选择简历文件和封面页来申请工作。

重要注意事项:

  • 我对 HTML5 或 flash 或棘手的解决方案不感兴趣 - 只是基本问题,是否可以在普通的旧浏览器中使用普通的旧 HTML。
  • 我可以接受多个上传字段和多个按钮来选择每个文件。
  • 一个提交按钮需要同时提交它们。
  • 需要支持IE6。

这可能吗?似乎很难找到直接的答案。

例如这样的东西会起作用吗? (我从网上的某个地方抓取它,抱歉,如果我没有注明来源)

<form action="/py/uploadfile" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <label>upload file<input type="file" name="file[]" id="file1" /></label>
    <label>upload file<input type="file" name="file[]" id="file2" /></label>
    <label>upload file<input type="file" name="file[]" id="file3" /></label>
    <label><input type="submit" name="button" id="button" value="Submit" /></label>
</form>

谢谢

html post file-upload
2个回答
2
投票

只需添加另一个

input[type="file"]
,并确保它具有不同的名称:

<form action="...">
    ...other fields...
    <input type="file" name="coverLetter" />
    <input type="file" name="resume" />
    ...other fields...
    <input type="submit" value="send" />
</form>

0
投票

确保在输入中包含 multiple="multiple",如下所示

<input type="file" multiple="multiple" name="files">

否则它将无法在 Firefox 上运行。

© www.soinside.com 2019 - 2024. All rights reserved.