Library tutorials & articles

Using the SAFileup component

The code

Next you see is the <input> tag having a type value as "FILE" so when you put this is a regular HTML page the browser understands that a file has to be uploaded and hence you see a button for "Browse..."

<input TYPE="FILE" NAME="fileUpload">

The submit code (below) on the other hand as below POST's the data to the server side and the file is uploaded to the directory specified.

<input type="submit" name="submiter" value="Submit">

Please make sure you have PWS/IIS running on your machine which supports server side code like ASP in this case.

Make sure you put all the files in the same virtual directory!

Recommended Spec

Windows 2000 (Win98 with PWS is also fine)
RAM: 128MB
IIS 4.0 and up (IIS 5.0 recommended)

The working code

<html>
<%
if Request.QueryString("uploader") = "true" then
   Set upl = Server.CreateObject("SoftArtisans.FileUp") ' Creating upl object!
   basePath  = Server.MapPath(".") ' mapping the default path where files will be stored on the hard disk!
   upl.Path = basePath & "\uploads"    
       
       if not upl.IsEmpty Then 'we check if the object is empty or has a null value!
           'on error resume next
           upl.Save 'Saving the uploaded file
           strFile = upl.UserFilename 'Storing name of the file in a temporary variable!
           strFileTemp = strFile
           aryFileName = Split(strFile,"\")
           lastVal = UBound(aryFileName) 'Checking the Ubound after spliting the file name!
           strFile = aryFileName(lastVal)
           strFileTemp = strFile    'actual file name with its type stored in a variable!        
       end If
end if
%>

<head>
<link rel="stylesheet" href="styler.css">
<script>
//This function checks to see if the user has selected some file using browse option
//If there is no proper path then it alerts user to please select a file.
function checkForm()
{
   if (document.form1.fileUpload.value.length>2)
   {
       return (true);
   }
   else
   {
       alert("Please select an image file to upload.");
       return (false);
   }
}
</script>
<title>Image Upload</title>
</head>
<body bgcolor="#edf3f8">
<form ENCTYPE="MULTIPART/FORM-DATA" ACTION="index.asp?uploader=true" METHOD="POST" id="form1" name="form1" onsubmit="javascript:return checkForm();">
<table width="100%">
       <tr>
           <td class="contentBold" height="20">
               Uploading files using SAFileup utility!<br>
           
           </td>
       </tr>
       <tr>
           <td class="content" height="20"></td>
       </tr>
   </table>
<%if Request.QueryString("uploader") = "true" then%>
   <table width="100%">
       <tr>
           <td class="content2" height="20">
               Your file <b><%=strFileTemp%></b> was successfully uploaded!<br><br>            
               <a class="upload" href=#" onclick="history.back(-1);">Click to upload more files.<a>
           </td>
       </tr>
       
   </table>
<%else%>
   <table width="100%">
       <tr>
           <td class="contentBold" height="20">
               Select an image file you would like to upload.<br>
               <input TYPE="FILE" NAME="fileUpload">
           </td>
       </tr>
       <tr>
           <td class="content"><img src="pixel.gif" height="10" width="1"></td>
       </tr>
   </table>
   <div align="left"><input type="submit" name="submiter" value="Submit"></div>
<%end if%>
</form>
</body>
</html>

Comments

  1. 13 Feb 2003 at 10:36

    Thanks for the help!!!
    I'm going to take a look to the sites you recommended.



    Regards,


    Pedro Röseler

  2. 11 Feb 2003 at 07:45

    Hello


    Javascript is a client side language so u cannot use javascript but server side java could be used but i don't know how


    there are heaps of other upload components out there and i there are also some pure asp upload pages out there aswell at planet-source-code.com and at http://www.4guysfromrolla.com/

  3. 06 Feb 2003 at 10:32

    Can anyone help me finding code to replace the SA fileup component with javascrip code so that i don't have to use that component?
    The server where i have a site that i build doesn't have that componet so i'm in big trouble!!!  ((


    Thanks!


    pedro


    pedro_roseler@mail.pt

  4. 01 Jan 1999 at 00:00

    This thread is for discussions of Using the SAFileup component.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

Related podcasts

  • ASP.NET Caching and Performance

    Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...

Related jobs