O'Reilly logo

Designing Active Server Pages by Scott Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Uploading Files from the Browser to the Web Server

One of the most frequently asked questions on the ASP Messageboard (http://www.aspmessageboard.com) is how to upload files from the client to the web server via an ASP page. Allowing your web visitors to upload binary documents has a number of practical applications. For example, a community site might allow its members to upload pictures of themselves; a job-hunting site might allow its applicants to upload their resumes in Word format; a software distribution site, like Tucows.com, might allow developers to upload their programs for download.

Uploading binary information to a web server is possible using existing HTML forms. To upload binary data, alter the HTML form tag so it contains an ENCTYPE and uses the POST METHOD:

<FORM ENCTYPE="MULTIPART/FORM-DATA"
      METHOD="POST"
      ACTION="URL for Form processing script">

Warning

You must explicitly set METHOD="POST" in your form tag; if you fail to do this, your ASP page that attempts to save the uploaded file will report an error. Also, if your visitors are using out-of-date browsers, they may not be able to upload files to the web server, since older browsers did not support the multipart/form-data standard. Internet Explorer started supporting the standard in Version 3.02, and Netscape has supported the standard since Version 2.0.

Then, to provide a text box and browse button in the form so the user can select a file to upload, use the INPUT tag with the TYPE set to FILE:

<INPUT TYPE="FILE" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required