Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  3rd Party Mail, CDO/CDONTS Listserver
     [next Lesson]  SA: File Upload, Multi-part form

Uploading with SA-FileUp -- Simple Example

by David Wihl

SA-FileUp is an Active Server component that allows users with a web browser to transmit files from their local hard disk to a Microsoft Internet Information Server (IIS) web server.

Scripting the Upload

Your file upload script(s) will consist of two parts:

  • An HTML form on the client
  • An instance of the SA-FileUp object on the server

To try SA-FileUp, browse to select a small file on you system and hit Upload File.

   filename=/sa/test/uploadsimple.asp

<Test Script Below>


<HTML><HEAD>
<TITLE>uploadsimple.asp by softwareartisans.com</TITLE>
</HEAD><body bgcolor="#FFFFFF">
<form enctype="multipart/form-data" method="post" action="uploadsimplerespond.asp">
<TABLE WIDTH="100%">
<TR>
    <TD ALIGN="RIGHT" VALIGN="TOP">Filename:</TD>

    <TD ALIGN="LEFT"><INPUT TYPE="FILE" NAME="FILE1">
    </TD>
</TR>
<TR>
    <TD ALIGN="RIGHT">&nbsp;</TD>
    <TD ALIGN="LEFT"><INPUT TYPE="SUBMIT" NAME="SUB1" VALUE="Upload File"></TD>
</TR>
<TR>
    <TD ALIGN="RIGHT">&nbsp;</TD>
    <TD ALIGN="LEFT">
    <B><I><SMALL>Note: if a button labeled "Browse..." does not appear, then your
    browser does not support File Upload. For Internet Explorer 3.02 users, a
    free add-on is available from Microsoft. If you <b>do not see a Browse... button</b> 
    <A HREF="http://www.microsoft.com/msdownload/ieplatform/iewin95/iewin95.asp" TARGET="_new">click here to go to Microsoft's Site and get your free file upload add-on</A>.
    Select "Internet Explorer 3.02 File Upload Add-On for Windows 95 & NT".
    </SMALL></I></B>
    </TD>
</TR>
</TABLE>
</form>
</BODY></HTML>

The Form Definition

To enable file upload, include an INPUT tag of <TYPE="FILE"> in your HTML form.

When using a form to upload files, you must set the following attributes:

  • The FORM tag must include the attribute ENCTYPE="multipart/form-data".
  • The <INPUT TYPE="FILE"> must include the NAME attribute.

The Server-side Processing

The responder to the form will look like this:

   filename=/sa/test/uploadsimplerespond.asp

<Test Script Below>


<HTML><HEAD>
<TITLE>Uploadsimplerespond.asp by softwareartisans.com</TITLE>
</HEAD><BODY>
Thank you for uploading your file.<br>
<% Set upl = Server.CreateObject("SoftArtisans.FileUp")
upl.Path = Server.Mappath ("/upload/tests")
upl.SaveAs "upload.tst"%><BR>
Total Bytes Written: <%=upl.TotalBytes%>
</BODY></HTML>

To process the upload on the server,

  • In the response page (in this case, uploadsimplerespond.asp) create an instance of the SA-FileUp object.
    <% Set upl = Server.CreateObject("SoftArtisans.FileUp") %>
  • Save the file in a directory on the web server.
    <% upl.SaveAs "C:\temp\upload.out" %>

The TotalBytes property contains the size in bytes of the uploaded file.

The directory on the web server must have Read, Write, and Delete NTFS permissions for the anonymous or authenticated user. Otherwise, SA-FileUp will not be able to write files into that directory. Talk to your web master about setting the appropriate permissions.

Chaz Wish List
Tall Tip $5
Grande Tip $20
Venti Tip $39
Tip Jar Thanks
2004 Thanks
2005 Thanks
HUGE Tip -love site