File select
   HOME

TheInfoList



OR:

In
HTML The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser. It can be assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaSc ...
, a file-select control is a component of a
web form A webform, web form or HTML form on a web page allows a user to enter data that is sent to a server for processing. Forms can resemble paper or database forms because web users fill out the forms using checkboxes, radio buttons, or text fields. ...
with which a user can select a local file. 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.


Code example

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.


Rendering

When it comes to the rendering on the screen of a file-select control, there is some variation among
web browser A web browser is application software for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's screen. Browsers are used o ...
s. 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 In computing, a file dialog (also called File Selector/Chooser, file requester, or open and save dialog) is a dialog box-type graphical control element that allows users to choose a file from the file system. They differ from file managers as th ...
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. Alternatively, instead of using the "Browse" button, the filename can be entered directly in the text field. Some browsers, notably
Firefox Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and its subsidiary, the Mozilla Corporation. It uses the Gecko rendering engine to display web pages, which implements current ...
, no longer allow a filename to be typed directly in. This is a security measure - it is possible to trick the user into uploading confidential information.


Functionality

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. HTML 4.01 does not, in itself, describe how the file-select control is supposed to work, but it does list RFC 2388 and RFC 1867 as references.


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.


Accept attribute

RFC 1867 also introduced the accept attribute for the input element. This would enable file-type filtering based on MIME type for the file-select control.
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: On a Windows platform, this might mean that the user agent would show files only of the types specified in the browse-file dialog.


Browser limitations

Basic support for the file-select control was adopted quickly by browser vendors. For example, already
Internet Explorer Internet Explorer (formerly Microsoft Internet Explorer and Windows Internet Explorer, commonly abbreviated IE or MSIE) is a series of graphical web browsers developed by Microsoft which was used in the Windows line of operating systems ( ...
4,
Netscape Navigator Netscape Navigator was a web browser, and the original browser of the Netscape line, from versions 1 to 4.08, and 9.x. It was the flagship product of the Netscape Communications Corp and was the dominant web browser in terms of usage share in ...
2.0 and
Opera Opera is a form of theatre in which music is a fundamental component and dramatic roles are taken by singers. Such a "work" (the literal translation of the Italian word "opera") is typically a collaboration between a composer and a libr ...
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 Chrome, Firefox, Internet Explorer, Safari and Opera. 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, 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 HTML5 ''File API'' aspect provides an API for representing file objects in web applications and programmatic selection and accessing their data. In addition, this specification defines objects to be used within threaded web applications for the sy ...
.{{cite web, url=https://developer.mozilla.org/en/Using_files_from_web_applications , title=Using files from web applications - MDC , publisher=Developer.mozilla.org , date=2013-08-23 , accessdate=2013-09-02 This feature also allows users to drag-and-drop files from external applications (such as
Windows Explorer File Explorer, previously known as Windows Explorer, is a file manager application that is included with releases of the Microsoft Windows operating system from Windows 95 onwards. It provides a graphical user interface for accessing the file ...
) directly into the web application. One notable example of support for this feature is
Gmail Gmail is a free email service provided by Google. As of 2019, it had 1.5 billion active users worldwide. A user typically accesses Gmail in a web browser or the official mobile app. Google also supports the use of email clients via the POP and ...
allowing attachments to be added in this way. HTML5 allows multiple file uploads using the ''multiple'' attribute on input elements.HTML 5.1 specification: 4.10.5.3 Common input element attributes
/ref>


JavaScript alternative

One solution is to use
client-side scripting A server-side dynamic web page is a web page whose construction is controlled by an application server processing server-side scripts. In server-side scripting, parameters determine how the assembly of every new web page proceeds, and includi ...
such as
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
for generating an extra file-select control for each file the user selects for upload. Using CSS, these extra file-select controls may be set not to display. An example of this technique is demonstrated in th
Multiple File Upload plugin
for
jQuery jQuery is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax. It is free, open-source software using the permissive MIT License. As of Aug 2022, jQuery is u ...
. In this manner, the multiple-file upload problem is solved by providing as many file-select controls as the user has files to upload. Still, this does not solve the problem of selecting multiple files for upload in Internet Explorer.


Accept attribute support

The accept attribute is currently supported by Opera 11+, Chrome 16+, Safari 6+, Firefox 9+ and Microsoft Internet Explorer 10+.


References


External links


Specification of the file select control from W3C
HTML