You are Here: FAQ ->Script Cookbook & Databases->ASP->Article #12


WebHosting Microsoft-Edition This Article is for 1&1 Microsoft Web Hosting Only.


How to set up ASP FileUp Component



ASP FileUp allows users with a web browser to transmit files from their local
system to a MS (IIS) web server. Files can be of any format. (word, gif, etc)

The most important thing with the Asp FileUp is setting up the Path. This path
will specify the place for the files to be uploaded (saved).

In this sample "uploads\data" is the path where "Asp FileUp" will upload the
file to.

Make sure you set the write permission on the subdirectory /data.
If you don't set write permissions a "permission error" will pop up when you run the
Asp FileUp Script.
To set write permissions please follow the FAQ: How to set permissions for directories

upload_file.asp
            
<% @Language=VBScript %>
<HTML>
<HEAD>
<TITLE>FileUp Upload Simple Sample</TITLE>
</HEAD>
<BODY>

<%
Dim oFileUp             

'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")

'--- Set the Path property to the location you wish to temporarily cache the incoming file before saving
oFileUp.Path = Server.MapPath("\uploads\data")

'--- Check if a file was selected (myFile is coming from the HTML code)
'--- If so, continue processing
If Not oFileUp.Form("myFile").IsEmpty Then

'--- Save the file
oFileUp.Form("myFile").Save

'--- The file is saved, display a confirmation message
Response.Write ("<B>File saved successfully on the server as:</B><BR>")

'--- The ServerName() property is the full path of the file where it was saved on the server
Response.Write(oFileUp.Form("myFile").ServerName)

Else
Response.Write("Error: There was no file submitted for upload.")
End If

'--- Destroy objects
Set oFileUp = Nothing
%>

</BODY>
</HTML>

          
A simple form will looks like this:
upload_file_form.htm


            
<HTML>
<HEAD>
<TITLE>FileUp Simple Upload Sample</TITLE>
</HEAD>
<BODY>
<H3 ALIGN=center>&nbsp;</H3> 
<H3 ALIGN=center>Asp FileUp Upload Sample</H3> 
<p ALIGN=center>&nbsp;</p>
<FORM ACTION="upload_file.asp" ENCTYPE="MULTIPART/FORM-DATA" METHOD="POST">
 <TABLE WIDTH="100%">
<TR>
<TD ALIGN="RIGHT" VALIGN="TOP">Enter Filename:</TD>

<!--
Note: Notice this form element is of TYPE="FILE"
--> 
<TD ALIGN="LEFT"><INPUT TYPE="FILE" NAME="myFile" size="20"><BR>
Please click Browse to select a file.</TD>
</TR>
<TR>
<TD ALIGN="RIGHT">&nbsp;</TD>
<TD ALIGN="LEFT"><INPUT TYPE="SUBMIT" VALUE="Upload File"></TD>
</TR>
</TABLE>
</FORM>

</BODY>
</HTML>
          


The script given here is a test script that you may want to incorporate into your
code. You would need to make sure that any paths referenced in the code are correct.


Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not Very Useful at all):
1 2 3 4 5