Introduction
The three ASP upload files include useful scripts for website developers and web masters. When installed correctly on your "Classic ASP" Microsoft IIS web server, the three ASP (Active Server Page) files will allow your users the ability to upload files to the web server. There are no components to install.
asp-uploader.zip contains three files:
- uploadform.asp: This file allows the user to select the file (from their computer) to upload to the web server. Once they select the file they want to upload, they click the upload button and the form calls the uploadexmple.asp.
The uploadform page only has a few lines of HTML code (15-20) to simply:
Supply the user with a textbox that browses to local files using:
<input type="file">
and submit the form and call a different page using:
<form method="post" action="uploadexmple.asp">
- uploadexmple.asp: This page calls an
Upload function within the upload.asp file. Once the upload is complete, this form displays the confirmation message (or error message).
The uploadexmple page has 55 lines of HTML code mixed in with VBScript. Once uploadform.asp calls the uploadexmple.asp file, the uploadexmple.asp file instantiates an instance of the FileUploader class (within upload.asp) like this:
Set Uploader = New FileUploader
Uploader.Upload()
- upload.asp: This file has 138 lines of VBScript code and contains two classes (
FileUploader and UploadedFile). The two classes are used to perform the actual upload from the client machine to the web server. The FileUploader class includes the Public Subroutine 'Upload' and utilizes Request.BinaryRead, Scripting.Dictionary, and Scripting.FileSystemObject.
After Uploader.Upload() is called from uploadexmple.asp and the uploadedfile is created in memory as a variable named FileData, uploadexmple.asp calls the SaveToDisk sub that writes the file to the web server with this code:
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.CreateTextFile(sPath & FileName, True)
For nIndex = 1 to LenB(FileData)
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
Next
oFile.Close
---------------------------
Brief Instructions to install:
- Place all three ASP files under the same folder within an IIS virtual directory (on your Classic ASP website). Note: The web folder that the ASP files reside in MUST have permission to create text files. Check these permissions in IIS.
- Change the 3rd line of uploadexmple.asp from C: to be the exact file location of where you want the upload files to be saved on the web server. If you fail to update this parameter, the script will attempt to save files to the root C:\ drive.
To test - Open a webpage on your web server and go to the uploadform.asp. Try uploading a file. If it uploads, check the disk location (specified in line 3 of uploadexmple.asp) to see if the file exists.
Troubleshooting - If the file is not there, try a smaller file. Otherwise, repeat instruction 2 in installation instructions.