Using Persits ASPUpload
Posted by Paul Woodland (Import) on 02 December 2006 04:35 AM

Persits ASPUpload is a server-side component that can be used to upload files from a client's machine to the server, under your domain.

How do you use Persits ASPUpload?
The following is an example of using the ASPUpload component to upload a file:

        'Create an instance of our ASPUpload object.
        Set uploadObj = Server.CreateObject("Persits.Upload")

        'We need to catch any errors
        On Error Resume Next
        uploadObj.Save Server.MapPath(".")
        If (Err <> 0) Then
            Response.Write "An error occured: " & Err.Description
        End If

The standard Request.Form collection becomes unusable when the Persits.Upload object is instantiated, to access the values of the Form collection, use something similar to this:

        formValue = uploadObj.Form("formField")
        'Where formField is a field input that was posted.

Posting a Form
When you post a form to your script, if it contains a file field (<input type="file" />), you need to specify an encoding type.  This can be done as follows:

    <form action="..." method="post" enctype="multipart/form-data">

Using SELECT (MULTIPLE) fields with ASPUpload
If you use a SELECT field in your posted form, with the MULTIPLE attribute, ASPUpload will store each selected value as an item in uploadObj.Form, and each item can be accessed individually:

        'Enumerate the Upload.Form collection.
        For Each Item In Upload.Form
            If (Item.Name = "select-field-name") Then
                'Do something.
                'Other Items.
            End If

The permissions on your hosting account are setup to allow scripts to operate in a secure manner.  Uploading files will work when the Save path is one that is under your domain.  Trying to save to files outside of your domain will result in an access violation and your script will finish in error.

(304 vote(s))
Not helpful

Comments (0)