In HTML, a file-select control is a component of a web form with which a user can select a file from his local machine. When the form is submitted (perhaps together with other form data), the file is uploaded to the web server. There, when the file arrives, some action usually takes place, such as saving the file on the web server. However, the particular action that takes place is determined by the server-side script to which the form is submitted.
Here is a code example of a web form with a file-select control. It is the
input element with
type="file" that creates the file-select control.
<form action="form-handler.php" method="post" enctype="multipart/form-data"> <div> <input id="myfile" name="myfile" type="file"> <input value="Upload ►" type="submit"> </div> </form>
When it comes to the rendering on the screen of a file-select control, there is some variation among web browsers. Typically, on a Windows-based platform, user agents will render a file-select control as a text field, together with a "Browse" button. When the "Browse" button is pressed, a file dialog opens, with which actual file selection on one's platform can take place. After selection, the filename of the selected file is displayed in the text field, with its full path. Alternatively, instead of using the "Browse" button, the filename can be entered directly in the text field.
The mechanism for form-based file upload was originally proposed in RFC 1867 (published November 1995), as an extension to HTML 2.0 (RFC 1866), after its publication. Form-based file upload then was incorporated in HTML 3.2, which explicitly refers to RFC 1867 for further information on form-based file upload.
Multiple file selection
The intention in RFC 1867 is that a single file-select control should allow selection of multiple files. This intention seems reflected in HTML 4.01, which, for the file-select control- type, states
This control type allows the user to select files so that their contents may be submitted with a form. The INPUT element is used to create a file select control.
It has been noted that the plural "files" in the above quote is an indication that, in HTML 4.01, a single-file select-control still was supposed to handle selection of multiple files and not just a single file.
This situation is being clarified in HTML5 by adding a "multiple" attribute when the file input should accept multiple files. The current draft specifies the new behavior to be:
Unless the multiple attribute is set, there must be no more than one file in the list of selected files.
In addition, it is proposed that the INPUT tag have an ACCEPT attribute, which is a list of comma-separated media types.
If an ACCEPT attribute is present, the browser might constrain the file patterns prompted for to match those with the corresponding appropriate file extensions for the platform.
Thus, a user-agent may restrict file selection, as, for example, in the following, restricted to GIF and PNG images or any images:
<input id="myfile" name="myfile" type="file" accept="image/gif,image/png"> <input id="myfile" name="myfile" type="file" accept="image/*">
On a Windows platform, this might mean that the user agent would show files only of the types specified in the browse-file dialog.
Basic support for the file-select control was adopted quickly by browser vendors. For example, already Internet Explorer 4, Netscape Navigator 2.0 and Opera 3.5 recognized the
input element of
type="file" as a file-select control.
However, most modern browsers still do not implement the file-select control as it was intended, or lack certain features.
Cannot select multiple files
Form-based upload of multiple files with a single file-select control is supported in current versions of Firefox, Safari, Opera, and Chrome, but not Internet Explorer. One source states that Opera supports multiple-file selection through a single file-select control. This was true for Opera versions starting from 3.5, in which the file-upload feature was introduced. However, with the first beta release of Opera 7 line, this function was no longer available. Firefox version 3.6 started supporting multiple-file selection, allowing the developer some limited access to the files themselves prior to being uploaded to the server, via the HTML5 File API. This feature also allows users to drag-and-drop files from external applications (such as Windows Explorer) directly into the web application. One notable example of support for this feature is Gmail allowing attachments to be added in this way.
HTML5 allows multiple file uploads using the multiple attribute on input elements.
Accept attribute support
The accept attribute is currently supported by Opera 11+, Chrome 16+, Safari 6+ and Firefox 9+ only.
The lack of support for multiple-file selection has led developers to search for alternative solutions. These solutions have in common that they do not use the
input type="file" element.
Several implementations of Flash-based file-upload utilities stopped working for users as they upgraded to Adobe Flash Player 10 released October 2008. 
- "388784 – (CVE-2007-3511) Firefox file input focus stealing vulnerability". Bugzilla.mozilla.org. Retrieved 2013-09-02.
- "Mozilla Firefox OnKeyDown Event File Upload Vulnerability". Juniper.net. 2010-11-15. Retrieved 2013-09-02.
- "HTML 4 Specification References". W3.org. Retrieved 2013-09-02.
- "Forms in HTML documents". W3.org. Retrieved 2013-09-02.
- "File input (or "upload") in HTML forms". Cs.tut.fi. Retrieved 2013-09-02.
- "HTML 5.1 Nightly". Dev.w3.org. 2004-02-05. Retrieved 2013-09-02.
- "input type=file Object". Msdn2.microsoft.com. 2013-07-22. Retrieved 2013-09-02.
- "Browser History: Opera". Blooberry.com. Retrieved 2013-09-02.
- on December 10, 2009 by Paul Rouget (2009-12-10). "multiple file input in Firefox 3.6 ✩ Mozilla Hacks – the Web developer blog". Hacks.mozilla.org. Retrieved 2013-09-02.
- "Using files from web applications - MDC". Developer.mozilla.org. 2013-08-23. Retrieved 2013-09-02.
- Posted by Adam de Boor, Software Engineer (2010-04-15). "Drag and drop attachments onto messages - Official Gmail Blog". Gmailblog.blogspot.com. Retrieved 2013-09-02.
- "Flash Player 10". Retrieved 2008-11-17.