[OnCloud] ASP Upload

Form To Upload Files

Here is a sample which consist of 2 parts, the HTML and the ASP code:

Please Note, this sample is for Windows accounts hosted on Windows 2003 server.

 

The HMTL File

<HTML>

<BODY BGCOLOR="#FFFFFF">

<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="/cgi-bin/Upload.asp">

<INPUT TYPE=FILE NAME="FILE1">

<INPUT TYPE=FILE NAME="FILE2">

<INPUT TYPE=FILE NAME="FILE3">

<INPUT TYPE=SUBMIT VALUE="Upload!">

</FORM>

</BODY>

</HTML>

 

Upload.asp in your /cgi-bin Directory

<%

Set Upload = Server.CreateObject("Persits.Upload.1")

' Upload files

Upload.OverwriteFiles = False ' Generate unique names

Upload.SetMaxSize 1048576 ' Truncate files above 1MB

Upload.SaveVirtual "/cgi-bin"

%>

 

Form To Email Files

The ASPUpload script can be customized to let website visitors attach files to an email form. Here's a sample:

 

The HTML File

<HTML>

<BODY BGCOLOR="#FFFFFF">

<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="/cgi-bin/Upload.asp">

<INPUT TYPE=FILE NAME="FILE1">

<INPUT TYPE=FILE NAME="FILE2">

<INPUT TYPE=FILE NAME="FILE3">

<INPUT TYPE=SUBMIT VALUE="Upload!">

</FORM>

</BODY>

</HTML>

 

Upload.asp in your /cgi-bin Directory

<%

Set Upload = Server.CreateObject("Persits.Upload.1")

' Upload files

Upload.SetMaxSize 1048576 ' Truncate files above 1MB

Upload.SaveVirtual "/cgi-bin/"

Set JMail = Server.CreateObject( "JMail.SMTPMail" )

JMail.ServerAddress = "mail.yourdomainname.com:25"

JMail.Sender = "admin@yourdomainname.com"

JMail.Subject = "Here you go..."

JMail.AddRecipient( "admin@yourdomainname.com" )

For Each File in Upload.Files

JMail.AddAttachment( "e:\\inetpub\\clients\\yourdomainname.com\\cgi-bin\\" & File.ExtractFileName )

Next

message = ""

For Each Item in Upload.Form

message = message & Item.Name & "= " & Item.Value & VBCrLf

Next

JMail.Body = message

JMail.Execute()

Set Jmail = Nothing

Set Upload = Nothing

%>

Notes and Troubleshooting

  1. The directory where the files will be uploaded MUST have the "write" permissions. The default setting on your account is to provide write permissions only to the /cgi-bin and /fpdb directories. However, "write" permissions can be provided to any directory by contacting us at support@myhosting.com.
  2. For security reasons, the "save" method is disabled. You need to use SaveVirtual method of ASPUpload.
  3. It is not necessary to have the files upload to the /cgi-bin. By default, you have "write" permissions to your cgi-bin and all related subdirectories. Additional permissions can be configured by contacting technical support at support@myhosting.com.
  4. An error that frequently occurs is:

Persits.Upload.1 error '800a0028'

This feature has been disabled by the system administrator. Impersonation of a user via ASPUpload is disabled by our system defaults (i.e. Upload.LogonUser is disabled).

  1. Another error that often occurs is the "Script timed out" error:
  2. The maximum amount of time for a script to execute was exceeded.
  3. You can change this limit by specifying a new value for the
  4. property Server.ScriptTimeOut or by changing the value in the

IIS administration tools.

This error can be quickly solved by inserting:

<% Server.ScriptTimeOut = 360 %>

as the first line of your code. This will set the timeout to 360 seconds.

  1. Restrictions or functions that are disabled on the component ASPUpload are Save method, COM object registration, changing ACLs, impersonating users, remove directory, file copy, file delete and directory listing (directory and file functions are already available via FileSystemObject).

 

Was this article helpful?
0 out of 0 found this helpful