How to upload multiple files on an HTML form

2019-08-12 05:41发布

问题:

I would have thought this would be super easy to find an answer to on the interwebs but apparently not.

On an HTML page, I wish to allow a user to select multiple files and upload them to my server. Specific context is that the user needs to choose a resume file and a cover page to apply for a job.

Important considerations:

  • I'm not interested in an HTML5 or flash or tricky solution - just the basic question, is it possible with plain old HTML in a plain old browser.
  • I am okay with having multiple upload fields and multiple buttons to choose each file.
  • A single submit button needs to submit them both.
  • Needs to support IE6.

Is this possible? It seems very hard to find a straight answer.

For example would something like this work? (I grabbed it from somewhere on the net sorry if I have not credited the source)

<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>

thanks

回答1:

Just add another input[type="file"], and make sure it has a different name:

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