Upload

This class implements an easy interface to upload files to a webserver.  It’s built using standard only functionallity in ASP.  It will automaticly start parsing the binary stream sent by the browser which might take a while if the uploaded files are large.

Notes

Large parts of this code is based on code by Gez Lemon of Juicy Studio http://www.juicystudio.com/.  It has been and partially rewritten and enhanced by CrazyBeaver Software along with it’s new class interface.

About

Summary
This class implements an easy interface to upload files to a webserver.
Stores Request.Form elements.
Stores File elements.
If an error occurs it’s message will be stored here.
Each entry of Upload.Files contains an object of this class.
File name.
File.
File mimetype.
Name of the input field in the form which the image came from.
Compute the file size.
Saves the binary in the hard drive.

Properties

Form

Stores Request.Form elements.

Contains

(scripting.dictionary) With the elements

Files

Stores File elements.

Returns

(scripting.dictionary) With the Upload_File objects

errorText

If an error occurs it’s message will be stored here.

Returns

(string) Error description

Upload_File

Each entry of Upload.Files contains an object of this class.  This is the class that user should use to retrieve information from the uploaded file.

About

Summary
File name.
File.
File mimetype.
Name of the input field in the form which the image came from.
Compute the file size.
Saves the binary in the hard drive.

Properties

name

File name.

Returns

(string) Name

data

File.

Returns

(binary) File

contentType

File mimetype.

Returns

(string) MIMEType

formName

Name of the input field in the form which the image came from.

Returns

(string) Name

Functions

size

public function size()

Compute the file size.

Returns

(int) Size

Example

dim oUpload, oFile
set oUpload = new Upload
for each oFile in oUpload.Files
    set oFile = oUpload.Files(oFile)
    Response.write(oFile.name & " has " & oFile.size & " bytes<br />" & vbCrLf)
    set oFile = nothing
next
set oUpload = nothing

saveToFile

public function saveToFile( sPath )

Saves the binary in the hard drive.

Parameters

(string)sPath Physical path

Returns

true if saveToFile is successful
false otherwise

Example

dim oUpload, oFile
set oUpload = new Upload
for each oFile in oUpload.Files
    set oFile = oUpload.Files(oFile)
    if(oFile.saveToFile(Server.mappath("saved/" & oFile.name))) then
        Response.write(oFile.name & " has been saved...<br />" & vbCrLf)
    end if
    set oFile = nothing
next
set oUpload = nothing
public function size()
Compute the file size.
public function saveToFile( sPath )
Saves the binary in the hard drive.