Knowledge Base Articles » KB100215: Using a Browser to Upload a File to a Web Server.
Developers are frequently presented with the task of retrieving a file from
a client's machine.
You cannot directly access the client machine's files. The client will have to send the data
voluntarily to the server. One way to allow them to
do this is with a file-selection control, e.g.
<input name="your_picture" type=file accept="image/*">
This type of control presents the client with a
text field, and a "Browse" button that allows them to select a file on their system.
The optional ACCEPT attribute restricts the types of files that will appear in the
file dialog box. The value of the ACCEPT attribute may be any list of MIME types.
In order to use file-selection controls, you must set the ENCTYPE attribute of the <form>
tag to "multipart/form-data" and the <form>
tag's METHOD attribute to "post". If you don't do this, the file selection field
will behave like an ordinary text field, and the file's pathname instead of its
contents will be sent. By setting the enctype attribute of the <form> tag to
"multipart/form-data", you will not be able to use
Request.Form
to retrieve the values
of the form fields. You will have to write server-side code using
Request.BinaryRead
to read
the contents of the http request, after which you will have to parse through this
information and manually extract the desired field values. Refer to
RFC 1341
and
RFC 1867
for details of the format of the request sent to the server.
In conclusion, a caveat: at present there is only partial support across browsers
for file upload buttons. Netscape Navigator versions 3.0 and 4.0 ignore the ACCEPT
attribute, and Internet Explorer version 3.0 completely fails to interpret file upload
buttons. Support seems consistent across later browsers, however.