Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
A100215: 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.
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
dgFileUpload
component will perform this task. This component allows you to upload files of any type to your server, via a "Request.Form"-type interface.
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.
The Guru
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information
knoxville photographer
knoxville wedding photographer