input type="file" Element


 

Module

The input type="file" element is an inline element declared by the XHTML 1.1 Forms Module but is not present in the *W3C XHTML 1.1 Basic Forms Module

Elements in the Forms Module are:
form | label | textarea | select | optgroup | option | button | fieldset | legend |
input type="button" | input type="checkbox" | input type="file" | input type="hidden" | input type="image" | input type="password" | input type="radio" | input type="reset" | input type="submit" | input type="text"

Description

The input type="file" element allows a file on the user's computer to be uploaded as part of a form submission.

In order to make use of file upload controls, the enclosing form element's enctype attribute should be given the value "multipart/form-data" and its method attribute the value "post". This allows the content of the file to be sent with the request. The server at the form's processing URI (specified in its action attribute) must take care of the request and store the uploaded file in the appropriate location, if required.

An example file upload control:

<label for="upload">File to upload:</label>
<input type="file" id="upload" name="upload" />

Note: I have not included value, readonly or maxlength attributes among the Specific Attributes on this page because browser support for these attributes is not consistent. In the case of the value attribute, which would give the page author the ability to specify a default file for upload (potentially without the user being aware of the upload taking place) presents such a security risk that almost all user agents ignore the contents of any value attribute on the input type="file" element. The maxlength attribute is also usually ignored (understandably, since the length of a file's filename is what it is and would not specify the location of the file correctly were it to be truncated!) and the readonly attribute gets only partial, if any, support in the majority of browsers (since I can't actually imagine a situation in which I would want to use this attribute, this doesn't strike me as a problem).

See also the overview of all input elements.

#REQUIRED Attributes

Although the type attribute is not #REQUIRED on the input element, its default value is "text" and so must be present on input type="file".


Specific Attributes

Specific attributes of the input type="file" element are listed below:

From the Forms Module - the Element's own Module

accept [ type ContentTypes ]
Comma-separated list of one or more content types (e.g. "image/jpeg") which will be accepted and handled correctly for this file input by the form's processing script
accesskey [ type Character ]
Key to be pressed which allows focus to be directed immediately to this input element to allow a file to be selected
disabled [ type Boolean ]
If this attribute is present, the file upload control is initially disabled - no data is sent to the processing URI for disabled elements when the form is submitted. The user cannot interact with a disabled control.
name [ type CDATA ]
This is the name sent to the processing URI for the file upload control when the form is submitted (if the name attribute is not present, the file data will not be sent). The value sent (in a name=value pair) is the filename selected (but bear in mind that some user agents will send the full path name and some just the name of the file itself).

To get file upload: In order to make use of file upload controls, the form element's enctype should be set to "multipart/form-data" and its method to "post" - this allows the content of the file to be sent with the request

Note: Although technically optional, a note in the *Forms Module DTD says that the name attribute is required on all input elements except "submit" and "reset"

size [ type Number ]
Initial display width of the file input field in characters (based on an average character width)
tabindex [ type Number ]
An integer between 0 and 32767 specifying the position of the file input field in the tabbing order of the document

From the Intrinsic Events Module

onblur [ type Script ]
Script to be executed when the element loses focus
onchange [ type Script ]
Script to be executed when the file selected is changed
onfocus [ type Script ]
Script to be executed when the element receives focus
onselect [ type Script ]
Script to be executed when some text within the upload file field is highlighted

Common Attributes

Common attributes of the input type="file" element are listed below:

From the Core Attribute Collection

class [ type NMTOKENS ]
One or more space separated classes
id [ type ID ]
A unique identifier for the element
style [ type CDATA ], from the Style Attribute Module (deprecated)
Element-specific styles
title [ type Text ]
Descriptive title for the element (in some user agents this may appear as a "tooltip" when the mouse hovers over the element)
xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]
XML namespace

From the I18N Attribute Collection

dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Module
Left-to-right or right-to-left directionality
xml:lang [ type LanguageCode ]
A language code for the element

From the Events Attribute Collection

All attributes in the Events Attribute Collection are supported:
onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup


Content Model

The Content Model for the input type="file" element is:

EMPTY

See Content Model & Nesting for information about Content Model syntax and Nesting Groups.

Valid children of input type="file"

This element is empty and may have no children.

Valid parents of input type="file"


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 01 Oct 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Element Index (XHTML 1.1) > input Elements > input type="file"