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
to retrieve the values
of the form fields. You will have to write server-side code using
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
and RFC 1867
for details of the format of the request sent to the server.
An easier way to retrieve the submitted file is by using a pre-built component, of
which there are many. If you are on a Windows platform, DevGuru's
component will perform this task.
This component allows you to upload files of any type to your server, via a
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.