我本以为在互联网上找到答案会非常容易,但显然不是。
在 HTML 页面上,我希望允许用户选择多个文件并将它们上传到我的服务器。具体上下文是用户需要选择简历文件和封面页来申请工作。
重要注意事项:
这可能吗?似乎很难找到直接的答案。
例如这样的东西会起作用吗? (我从网上的某个地方抓取它,抱歉,如果我没有注明来源)
<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>
谢谢
只需添加另一个
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>
确保在输入中包含 multiple="multiple",如下所示
<input type="file" multiple="multiple" name="files">
否则它将无法在 Firefox 上运行。