HTML File Upload Input Generator
WM-55Describe the upload field and get a labelled file input, with the accept filter and a form that has the right encoding.
Runs in your browser. Nothing is uploaded.
Attribute lines: label:, name:, id:, accept:, hint:, action:, button:
HTML
How to use it
- Write label: and name:, and an accept: line with extensions or MIME types such as .pdf, image/*.
- Tick Allow several files if users may pick more than one.
- Tick the form option to add a form with method post and multipart/form-data, and give action:.
- Copy the HTML into your page.
What accept does and does not do
The accept attribute is a comma-separated list of extensions such as .pdf, exact MIME types such as image/png, and wildcards such as image/* or audio/*. Browsers use it to filter the file picker and to preselect a type, but the user can often switch to all files, and a file with a wrong extension can still be chosen. It is a convenience, not a security check, so confirm type and size on the server. The tool rejects values that are not one of those three forms.
Why the form needs multipart/form-data
A form can only send file contents when its method is post and its enctype is multipart/form-data. With the default encoding the browser sends just the file name. When you tick the form option the tool writes both, and it refuses the get method for this input. The tool only writes markup: no file is read, selected or sent from this page.
Multiple files and what scripts can read
The multiple attribute lets the user choose more than one file at once. Script can read the chosen files from the input's files list, which holds name, size and type for each. The input's value property shows a fake path, not the real location on disk, which browsers hide on purpose. You also cannot preset a file with a value attribute, so this generator has no value line for file inputs.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
A file input needs the post method: files cannot be sent with get. | The form option is on with the get method. | Switch the Form method option to post. |
Questions people ask
How do I limit an upload to PDF files?
Add accept=".pdf" or accept="application/pdf". This filters the picker only. Check the file type again on the server. Because the picker filter is only a hint, users can still pick other files, so check the type and size on your server.
Does accept stop users choosing other files?
No. It filters and hints. Users can often change the picker to show all files, so validate on the server. A renamed file can also slip through, because the check is by name or reported type only. Treat the server as the real gatekeeper.
What is multipart/form-data for?
It is the form encoding that carries file contents. Use it with method post on any form that has a file input. Without it, only the file name is sent.
How do I let users upload several files?
Add the multiple attribute to the input. Then read all chosen files from the files list in script, or let the server receive them as repeated parts with the same name.
Can I set a default file in the input?
No. For security, browsers do not allow a page to preset a file. The value shown after choosing is a fake path. If you need to resume an upload, keep the earlier progress on your server and ask the user to choose the file again.
About this tool
Builds a label and an input of type file. The accept line takes extensions such as .pdf, MIME types such as image/png and wildcards such as image/*; it only filters the file picker and does not stop a different file being chosen, so check type and size on the server. The size limit in a hint is text only. Choosing the form wrapper adds a form with method post and enctype multipart/form-data, which a file upload needs; the get method is refused for this reason. This tool builds the markup only: no file is read or sent from this page.