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:

      ACTION="URL for Form processing script">


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:


Get Designing Active Server Pages now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.