Using the input Element to Upload Files
Description
The file input element uploads files to the server during the form submission.
This type of input supports the additional attributes shown as follows.
- accept - Specifies the set of mime-types that will be accepted. RFC2046 defines MIME types (http://tools.ietf.org/html/rfc2046).
- multiple - Specifies that the input element can upload multiple files. At the time of writing, none of the mainstream browsers have implemented this attribute.
- required - Specifies that the user must provide a value for the purposes of input validation.
Example
The following code shows the file type of input element in use.
<!DOCTYPE HTML>
<html>
<body>
<form method="post" action="http://example.com/form"
enctype="multipart/form-data">
<p>
<input type="file" name="filedata" />
</p><!--from w w w . j a v a2 s . c o m-->
<input type="submit" value="Submit" />
</form>
</body>
</html>
You can upload files only when the encoding type for the form is multipart/form-data.
When the user clicks the Choose File button, they are presented with a dialog that allows a file to be selected.
When the form is submitted, the contents of the file will be sent to the server.