Quick Search for:  in language:    
COM,ADODB,FAQ,Allows,upload,multiple,files,fi
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 196,174. lines
 Jobs: 103. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Server Side PDF
By Igor Krupitsky on 11/20


Click here to see a screenshot of this code!Multiple Web Sites on one IP
By Richard J Mackey on 11/20

(Screen Shot)

Click here to see a screenshot of this code!Multiple websites on One IP
By Richard J Mackey on 11/20

(Screen Shot)

Click here to see a screenshot of this code!Combo-Box with Auto-Complete
By Mark Kahn on 11/18

(Screen Shot)

Click here to see a screenshot of this code!RegEx pattern match in VBScript
By moppy on 11/18

(Screen Shot)

Click here to see a screenshot of this code!Text-to-Speech in MS Outlook
By Nick Sumner on 11/18

(Screen Shot)

Click here to see a screenshot of this code!Rapid Classified Board v1.0 (beta)
By Gurgen Alaverdian on 11/17

(Screen Shot)

Adjust a GIF's Hue/Sat/Lum
By Mark Kahn on 11/17


Search Engine
By vsim on 11/17


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Upload Files Without COM v3

Print
Email
 

Submitted on: 9/1/2003 11:19:59 PM
By: Lewis Moten  
Level: Advanced
User Rating: By 24 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this article 5097 times.
 

(About the author)
 
     Allows you to upload multiple files and fields without purchasing or registering COM objects. Great for shared hosts that frown upon 3rd Party com objects or charge an arm and a leg for them. This script provides an object oriented interface using classes for easier development. The power that this script has over others is that it does not use dictionary objects to store the uploaded files. It also harnesses the power of ADODB to prepare and save binary data to the file system with quick speeds. This is the script that you have been looking for. You can get a really good feel for how the script is used just by reading through the FAQ and examples provided. This script has been tailored to meet the requests of developers who have used previouse versions. The code is comented very well and comes along with examples of how to do common operations, as well as a FAQ. Bugs from version 2 have been fixed, or otherwise throw exceptions to the user giving them details of how to correct the problem (such as giving permission to the internet user account). Memory is managed more efficiently in version 3 that allows for more scaleablity and larger files. By the request of a few developers, progress bars are now supported to notify the user how much information has been received by the server. A website for support has also been created where you can get help from the author, other users of the script, and get any recent revisions or additional examples as they become available.

This article has accompanying files

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

Upload Files without COM

Created by Lewis Moten

I have gone through the internet and my email trying to collect many of the questions that I have received in the past concerning version 1 and 2 of the Upload Files without COM scripts. I have also tried to display examples for common scenarios that many of you will use. Please read through this FAQ fully before sending me a question. 

General Information

  1. What does it do?

    This script allows you to upload multiple files and fields without purchasing or registering COM objects. It is ideal for shared hosts that frown upon 3rd Party com objects or charge an arm and a leg for them.

    This script provides an object oriented interface using classes for easier development. The power that this script has over others is that it does not use dictionary objects to store the uploaded files. It also harnesses the power of ADODB to prepare and save binary data to the file system with quick speeds. This is the script that you have been looking for. You can get a really good feel for how the script is used just by reading through this FAQ.

    The code is commented very well and comes along with examples of how to do common operations, as well as the FAQ you are reading now. Bugs from version 2 have been fixed, or otherwise throw exceptions to the user giving them details of how to correct the problem (such as giving permission to the internet user account). Memory is managed more efficiently in version 3 that allows for more scalability and larger files.

  2. What is new in version 3?

     

    • Better control over memory management.
    • Detailed errors with suggestive fixes for user errors.
    • Fixed errors reported by other users that could be duplicated
    • File Management (Move, Copy, Rename, Delete)
    • Assignment of default file name if none were provided
    • Introduced ability to display upload progress meter
    • Method to return a similar unique file name not used within a folder
    • Method to return a collection of fields assigned the same field name
    • First FAQ was created
    • Debug method to write contents of posted data for developers and troubleshooting
    • Structure documented in separate file.
    • Mug shot of the developer

     

  3. What are the requirements?

    You should have Microsoft Data Access Components (ADODB) 2.6 or later installed. Also, you need to have Microsoft Windows Script 5.5 or later installed as well. Many ISP's have this installed by default. If your ISP does not have them installed, you can direct them to download the software from Microsoft's website for free.

    http://www.microsoft.com/data - Microsoft Data Access Components
    http://www.microsoft.com/scripting - Microsoft Windows Script

    I would also like to point out that you must run this script on a website that can process ASP scripts. You can not view these scripts from your file system. You will have to type in a URL in your web browser beginning with http://. Microsoft provides a web server called Internet Information Server (IIS) for servers and Personal Web Server for personal computers. Personal Web Server was made available with Windows NT 4.0 Option Pack, but is compatible with Windows 9x operating systems.

    http://www.microsoft.com/iis - Internet Information Services
    http://www.microsoft.com/ntserver/nts/downloads/recommended/NT4OptPk/default.asp - Windows NT 4.0 Option Pack

  4. How much does your script cost?

    The script is free to use within your website. I do ask that you register this script at http://upload.lewismoten.com.  Monetary donations (large and small) are accepted through PayPal with my account, Axiom Studios, Inc. If you would like to donate equipment, hosting space, or software, please contact me at lewis@moten.com.

    Make a donation via paypal to lewis@moten.com

  5. Can I modify your script?

    Yes, you may modify it for your own website, but you may not publish or distribute the code without my written permission. Simply put, if you are making money with my script, I would appreciate some acknowledgement, funds, hosted space and/or hardware to encourage my development for the open source community. Email me for more details.

  6. How can you claim to upload files without COM?

    I am aware that since version 2, I have used the MDAC components (ADODB) to speed up the upload process. If you want to get technical, using the Request object is a COM component. I could rename this script to upload files without having to install additional COM on most current standard windows operating systems. Instead, I kept the name simple and to the point. It is the first thing people start looking for when they need the solution that I provide.

  7. What browsers / operating systems are needed by my visitors?

    Microsoft Internet Explorer 6.0 appears to work fine on the Windows Platform.
    Mozilla 1.4 works ok on Windows. I have had problems when dealing with Unicode.

    I have heard that users with Macintosh computers have problems. If someone has a spare Mac that they would like to donate, then I would be willing to take the time to fix up the script to support them.

Getting Started

  1. How do I install the scripts?

    These instructions are written for those of you who have access to the computer with a default installation of IIS. Some steps may have to be changed according to your setup.

    The upload script depends on three different scripts. These are clsField.asp, clsUpload.asp, and clsProgress.asp. In your website, do the following:

    1. Create folder called Upload in your c:\Inetpub\wwwroot directory.
    2. Copy clsUpload.asp to the folder
    3. Copy clsField.asp to the folder
    4. Set the permissions for your Internet Guest Account to have the rites to write, read, and modify the upload folder.
    5. Create an ASP page called Form.asp with the following code:
      <FORM method="post" encType="multipart/form-data" action="Upload.asp">
      <INPUT type="File" name="File1">
      <INPUT type="Submit" value="Upload">
      </FORM>
    6. Create an ASP page called Upload.asp with the following code:
      <!--#INCLUDE FILE="clsUpload.asp"-->
      <%
      Dim Upload
      Dim Folder
      Set Upload = New clsUpload
      Folder = Server.MapPath("Uploads") & "\"
      Upload("File1").SaveAs Folder & Upload("File1").FileName
      Set Upload = Nothing
      %>
    7. Visit the Form.asp page in your browser. http://localhost/Upload/Form.asp http://localhost/Upload/Form.asp

    Hopefully, everything worked fine and you are on your way. Some of the steps may need to be changed, according to the location of your website.

  2. How do I setup permissions on the folder I wish to upload to?

    Open up your file explorer and locate the folder that you wish to update files to. Right mouse click the folder and click Properties. Click the Security tab. You will see a list of users who have access to the folder. Click the Add button and locate a user beginning with "IUSR_", it will be followed by the name of your computer. This is called the Internet Guest Account. When you click on the user in the list of assigned users, you will need to verify that they have access to write, modify and read.

  3. How do I upload 2 or more files at once?

    Add additional INPUT tags to your form for uploading files. Give each one a different name, such as File1, File2, etc.

    <INPUT type="file" name="File1">
    <INPUT type="file" name="File2">
    <INPUT type="file" name="File3">
    Dim Upload
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    Folder = Server.MapPath("Uploads") & "\"
    Upload("File1").SaveAs Folder & Upload("File1").FileName
    Upload("File2").SaveAs Folder & Upload("File2").FileName
    Upload("File3").SaveAs Folder & Upload("File3").FileName
    Set Upload = Nothing
  4. How do I upload other information in the form at the same time?

    You can add additional input elements that are different types.

    <INPUT type="file" name="File1">
    <INPUT type="text" name="Description">
    Dim Upload
    Dim Description
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    Description = Upload("Description").Value
    FileName = Upload("File1").FileName
    Folder = Server.MapPath("Uploads") & "\"
    Upload("File1").SaveAs Folder & FileName
    Set Upload = Nothing
    Response.Write "Description: " & Description
  5. How do I display a progress meter?

    The progress meter is a little tricky, but I have done most of the work for you in determining how it can be done.  When the user clicks the Submit button, you will need to open a Popup window that will display the status for the current upload session.  Sessions are identified by passing a query string to both the Popup window, and the ASP file that processes the upload.  This session should be a random number, or you will run the risk of your users seeing progress for someone else's upload.

    One of the most important rules for the progress window is that you must disable session state for the ASP page.  You can leave session state active for the rest of your website, but this page can not use it.  If session state is enabled, then your progress window will appear to hang until the upload has completed.  To disable session state in one page, you can use the following tag at the top of your page: <%@ EnableSessionState=False %>

    <FORM onsubmit="return UploadForm_submit()" method="post" action="Upload.asp" name="UploadForm" encType="multipart/form-data">
    <INPUT type="file" name="File1">
    <INPUT type="submit" value="Upload">
    </FORM>
    <SCRIPT language="javascript">
    function UploadForm_submit()
    {
    // Create a random session identifier.
    var Session = new String();
    Session = Math.floor(Math.random() * 0xFFFFFF).toString(16);

    // append identification of session
    document.UploadForm.action += "?Session=" + Session;

    // open the pop-up window
    window.open("Status.asp?Session=" + Session ,"upload","width=200,height=200");
    }
    </SCRIPT>
    <%@EnableSessionState=False%>
    <!--#INCLUDEFILE= "clsProgress.asp"-->< BR> <%
    Dim Progress
    Set Progress = New clsProgress
    Progress.Load
    Response.Write "Uploaded "
    Response.Write Progress.BytesReceived
    Response.Write " of "
    Response.Write Progress.TotalBytes
    Set Progress = Nothing
    %>
    <SCRIPT language="javascript">
    // reload this page after 1 second.
    window.setTimeout("window.location.reload()", 1000);
    </SCRIPT>

    The progress class exposes the basic information about your upload session.  View the structure documentation for a list of all of its methods and properties.  With this information, you can create your own progress meters.  An example progress meter has been included for you with the original script package called Progress_Status.asp.

  6. How do I access a collection of fields with the same name?

    A collection is sent when you have a select list that allows for more then one item to be chosen, or if you have multiple fields with the same name on your form. In the past, this was a little tricky to access, but now a new feature has been introduced. You can access an array of fields by calling the Collection method on the Upload object. Each field of the form is sent, in the order in which it occurs in the form.

    <SELECT multiple size="3" name="Colors">
        <OPTION selected value="#ff0000">Red
        <OPTION selected value="#ffffff">White
        <OPTION value="#0000ff">Blue
    </SELECT>
    Dim Upload
    Set Upload = New clsUpload
    Dim Colors
    Dim Color

    Colors = Upload.Collection("Colors")
    For Each Color In Colors
        Response.Write Color.Value & "<BR>"
    Next

    Set Upload = Nothing

Managing Existing Files

  1. How do I delete files?

    The upload object has a routine called DeleteFile. Pass the full path to the file to this routine.

    Dim Upload
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    FileName = Upload("File1").FileName
    Folder = Server.MapPath("Uploads") & "\"
    Upload.DeleteFile Folder & FileName
    Upload("File1").SaveAs Folder & FileName
    Set Upload = Nothing
  2. How do I rename a file in my file system?

    The upload object has a routine called RenameFile. Pass the full path to the file to this routine, and the new name of the file.

    Dim Upload
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    FileName = Upload("File1").FileName
    Folder = Server.MapPath("Uploads") & "\"
    Upload.RenameFile Folder & FileName, "NewFileName.gif"
    Upload("File1").SaveAs Folder & FileName
    Set Upload = Nothing
  3. How do I copy a file in my file system?

    The upload object has a routine called CopyFile. Pass the full path of the current file to this routine, and the full path to the target location.

    Dim Upload
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    FileName = Upload("File1").FileName
    Folder = Server.MapPath("Uploads") & "\"
    Upload.CopyFile Folder & FileName, Folder & "NewFileName.gif"
    Upload("File1").SaveAs Folder & FileName
    Set Upload = Nothing
  4. How do I move a file in my file system?

    The upload object has a routine called MoveFile. Pass the full path of the current file to this routine, and the full path to the target location.

    Dim Upload
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    FileName = Upload("File1").FileName
    Folder = Server.MapPath("Uploads") & "\"
    Upload.MoveFile Folder & FileName, Folder & "NewFileName.gif"
    Upload("File1").SaveAs Folder & FileName
    Set Upload = Nothing

File Restrictions

  1. How do I restrict the user from uploading certain file extensions? (EXE, BAT, COM, VBS, etc.)

    The field object has a property called FileExt. You can check this to verify that the file extension is valid, or a potential risk.

    Dim Upload
    Dim FileName
    Dim Folder
    Dim Ext
    Set Upload = New clsUpload
    Ext = Upload("File1").FileExt
    Select Case Ext
    Case "GIF", "JPG", "PNG", "BMP"
        FileName = Upload("File1").FileName
        Folder = Server.MapPath("Uploads") & "\"
        Upload("File1").SaveAs Folder & FileName
    Case Else
        Response.Write "File type not supported."
    End Select
    Set Upload = Nothing

    Although a filenames extension may be valid, it may still contain harmful information. Imagine a scenario where a user creates a virus and renames it to photo.gif. This will get past your file extension validation. You may wish to use other scripts or components to validate the binary data as well. You can use another script I crated called Read Image Dimensions to help aid you in verifying a files actual content when dealing with images. The class clsImage is included with this distribution of Upload Files without COM.

    Dim Width
    Dim Height
    Set Upload = New clsUpload
    Set Image = New clsImage
    Image.DataStream = Upload.Fields("File1").BinaryData
    Select Case Image.ImageType
    Case "GIF", "JPG", "PNG", "BMP"
        FileName = Upload("File1").FileName
        Folder = Server.MapPath("Uploads") & "\"
        Upload("File1").SaveAs Folder & FileName
    Case Else
        Response.Write "File type not supported."
    End Select
    Set Image = Nothing
    Set Upload = Nothing
  2. How do I get image pixel dimensions (height x width)

    I have published another script that supports this called Read Image Dimensions. It is included with this distribution as clsImage.asp.

    With the Image Script, you can either read a file from the file system, or pass the binary data of the image to be read to it. You can then verify if the image size falls within your requirements and notify the user if it does not.

    Dim Width
    Dim Height
    Set Upload = New clsUpload
    Set Image = New clsImage
    Image.DataStream = Upload.Fields("File1").BinaryData
    If Image.Width > 640 Then
        Response.Write "Image is too wide. It must be 640x480 or less."
    ElseIf Image.Height > 480 Then
        Response.Write "Image is too high. It must be 640x480 or less."
    Else
        FileName = Upload("File1").FileName
        Folder = Server.MapPath("Uploads") & "\"
        Upload("File1").SaveAs Folder & FileName
    End If
    Set Image = Nothing
    Set Upload = Nothing
  3. How do I limit the file size that a user can upload?

    Each field that you upload has a Length property. You can check the length to make sure it is a specific size or less.

    Dim Upload
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    If Upload("File1").Length <= 1048576
        FileName = Upload("File1").FileName
        Folder = Server.MapPath("Uploads") & "\"
        Upload("File1").SaveAs Folder & FileName
    Else
        Response.Write "File size must be 1 megabyte or less"
    End If
    Set Upload = Nothing
  4. Can the user select mulitple files at once?

    No. This is a restriction of the input element. However, you can have multiple input elements on one page. The visitor will have to populate each one with the location of the file on there computer.

Working with Databases

  1. How do I upload a file into a database?

    The Field object has a property called BLOB. This can be saved directly into the database.

    Dim Upload
    Dim FileName
    Dim Connection
    Dim RecordSet
    Dim ConnectionString

    ' One of these may work for you, depending on your systems configuration
    ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Files.mdb")
    ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Files.mdb")

    Set Upload = New clsUpload
    FileName = objUpload.Fields("File1").FileName

    Set Connection = Server.CreateObject("ADODB.Connection")
    Set RecordSet = Server.CreateObject("ADODB.Recordset")

    Connection.Open ConnectionString

    RecordSet.Open "Files", Connection, 3, 3

    RecordSet.AddNew

    RecordSet.Fields("FileName").Value = objUpload.Fields("File1").FileName
    RecordSet.Fields("FileSize").Value = objUpload.Fields("File1").Length
    RecordSet.Fields("ContentType").Value = objUpload.Fields("File1").ContentType
    RecordSet.Fields("BinaryData").AppendChunk objUpload("File1").BLOB & ChrB(0)

    RecordSet.Update

    RecordSet.Close

    Set RecordSet = Nothing
    Set Connection = Nothing
    Set Upload = Nothing
  2. How do I retrieve a file from the database?

    You can use the BinaryWrite method on the Response Object

    Dim Connection
    Dim RecordSet
    Dim ConnectionString
    Dim FileID
    Dim Sql

    ' One of these may work for you, depending on your systems configuration
    ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("Files.mdb")
    ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("Files.mdb")

    FileID = Request.QueryString("FileID")


    Set Connection = Server.CreateObject("ADODB.Connection")
    Set RecordSet = Server.CreateObject("ADODB.Recordset")

    Connection.Open ConnectionString

    Sql = "SELECT FileName, ContentType, BinaryData FROM Files WHERE FileID = " & FileID

    RecordSet.Open Sql, Connection, 3, 3

    If Not RecordSet.EOF Then
        Response.AddHeader "content-disposition", "attachment; filename=" & RecordSet("FileName")
        Response.AddHeader "content-length", RecordSet("BinaryData").ActualSize
        Response.ContentType = RecordSet("ContentType")
        Response.BinaryWrite RecordSet("BinaryData")
    Else
        Response.Write("File could not be found")
    End If

    RecordSet.Close
    Connection.Close

    Set RecordSet = Nothing
    Set Connection = Nothing
  3. How do I display a picture from the database?

    You can work with the code that retrieves files from the database. Just reference the web page in your image tag.

    <IMG src="Download.asp?FileID=327">
  4. How do I setup permissions on the Access database I wish to write in?

    This is very similar to setting up permissions for folders. Rather then right-clicking on the folder, you can right-click on the file itself. The only permissions that you will need to verify are that they have access to read and modify the file.

  5. What kind of data type should I use with a Microsoft Access database?

    Microsoft Access can store binary data in fields defined as OLE Object.

  6. What kind of data type should I use with a Microsoft SQL Server?

    SQL Server has a few data types to store binary data. The quickest one to identify is the binary data type. This one is like a varchar data type (where you specify how long your data can be). The data type that I prefer to use is the image data type (similar to the text and ntext fields). The image data type holds a 16 byte pointer to your actual binary data and has a size limit of roughly 2 gigabytes. If you wish to restrict your data so that a file can not be stored that is greater then a certain size, then go with the binary data type, other wise - use image.

File Names

  1. How do I let the user choose the name of the file?

    You can provide an extra text field and use this when saving the file. When the user sends the file over, you can then save the file with the suggested name.

    <INPUT type="file" name="File1">
    <INPUT type="text" name="FileName">
    Dim Upload
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    FileName = Upload("FileName").Value
    Folder = Server.MapPath("Uploads") & "\"
    Upload("File1").SaveAs Folder & FileName
    Set Upload = Nothing
  2. How do I make the file unique, if it already exists?

    The upload class provides a method called UniqueName. You may pass the proposed file name, and the path of the folder that you wish to store it within. If a duplicate file name already exists within the folder, it will iterate through an index until it finds a name that does not yet exist.

    If you upload a file called Photo.JPG 3 times, and use the UniqueName method each time, then you will have 3 files with the following names: Photo.JPG, Photo[1].JPG, Photo[2].JPG.

    Dim Upload
    Dim FileName
    Dim Folder
    Set Upload = New clsUpload
    FileName = Upload("File1").FileName
    Folder = Server.MapPath("Uploads") & "\"
    FileName = Upload.UniqueName(Folder, FileName)
    Upload("File1").SaveAs Folder & FileName
    Set Upload = Nothing
  3. What happens if the file exists on the file system?

    The file is overwritten. You can use the UniqueName method to make sure that files are not over written by assigning them different names if a file with the same name already exists.

Performance

  1. Is there anything I can do to speed up uploads?

    You can modify the number of bytes read at a time when the posted form data is read.  This property can be found within clsUpload.asp.   By default, the setting is 64 KB.  Remember, as you decrease the value, the buffer is read and processed more often.  If you are saving progress information, then a file is opened and written to each time as well.  However, if you make the buffer too large, then your clients' progress window will not appear to get new information as often.

    Do not setup your buffer to be under 100 bytes, or you may risk not being able to parse the data property for each field that had been posted to the web page.

    Const BufferSize = &H10000

    For your reference:

    Kilobytes Bytes Hex Value
    1 KB 1024 &H400
    2 KB 2048 &H800
    4 KB 4096 &H1000
    8 KB 8192 &H2000
    16 KB 16384 &H4000
    32 KB 32768 &H8000
    64 KB 65536 &H10000
    128 KB 131072 &H20000
    256 KB 262144 &H40000
  2. How large can my files be?

    The answer is not known. Some developers have mentioned that the script has worked perfectly with files over 100 MB for version 2. Others have mentioned that it begins to have problems when the files go up to that size, or even over 1 MB. It depends on your web servers' resources and connection speed to the visitor. It also depends if you are working with the latest version, as each one usually increases in performance.

    As each version is released, it becomes more scaleable to allow larger file sizes. Hopefully, this version will allow more developers to approach the 100 MB test with success.

    Version 2 helped increase the speed and take less memory to upload a file by introducing ADO Streams to handle conversion. Version 3 improves on the memory by constantly going to a central location to retrieve binary data rather then make small copies of it for each file uploaded. Also, data is not parsed until your code asks for it.

  3. How well does vbScript handle the String Concatenations?

    One of the downfalls of vbScript (and Visual Basic) is that in order to concatenate a string, you must copy it into memory twice. Take the following for example: (myString = myString & "xxxxx"). It is copied once to be assigned, and the other time is copied as the string being assigned.

    This was a large problem with version 1 and slowed things down a lot when pulling binary content from the posted form data. The process was sped up by assigning a large chunk of the data to an ADODB.Stream object to convert the binary data for us. A lot of you who used version 1 were amazed when version 2 came out.

    Two internal functions still remain that have a lot of concatenation (CStrU and CStrB). These two methods convert between Unicode and ASCII strings one character at a time. This is one of the last bottle necks left due to limitations of ASP. As long as your text values are small, the methods will not spend too much of your servers resources to convert the data. If you post a large resume in a TEXTAREA, then you may begin to see noticeable results.

Miscellaneous Questions

  1. Does the script support double-byte character file names?

    Part of this question depends on your web server, another part depends on your web browser, and the last part depends on how well I've put my code together without knowing how to deal with Unicode. Your file names and content of the file may not transfer properly. I make no guarantees.

    With that said, I don't have much to go on. From what I can understand, you may have to modify Meta tags and code pages on the server before you can properly test if this script supports double byte characters. I tried copying some double-byte characters from the internet and pasting it into one of my file names. After I had uploaded it with MSIE, the file was renamed. I tried this on both Windows XP and a Windows 2000 Server with the same exact results.

    I tried copying the characters into the contents of a text file, and saved the file as Unicode. After uploading the file, I was still able to see the correct Unicode characters within it.

    I tried the same tests with Mozilla 1.4. It replaced all the Unicode characters in the filename to underscore characters. Also, it only sent one byte of the files data across the line.

    If you have had success or suggestions, please share your findings by sending me an email.

  2. How do I remove your signature from the error messages?

    Just do a search for any portion of the signature in the ASP code. You may find it within an area where the class initializes. Please do not pass the code along to others after you had made changes.

  3. What else can your script do?

    If you are really interesting the full potential of what the script can do, take a look at the source code. It is commented very well so that even beginners can get a rough idea about what is happening.

  4. Does your script work with ChilisoftASP or iASP?

    I do not know. If you have ChilisoftASP or iASP, please try it out and tell me what the results are.

    http://wwws.sun.com/software/chilisoft/index.html - Sun ONE Active Server Pages 4.0 - Chili!soft.ASP
    http://www.halcyonsoft.com/ - Halcyon Software - iASP, Instant ASP

  5. Where can I get detailed information about uploading files?

    You can find this information if you search the internet for RFC 1867. (A.k.a. Request for Comments). As taken from the document itself, here is its explanation:

    This memo defines an Experimental Protocol for the Internet community. This memo does not specify an Internet standard of any kind. Discussion and suggestions for improvement are requested. Distribution of this memo is unlimited.

    This was back in 1995. RFC 1867 is no longer experimental. It is a widely accepted Internet standard.

Trouble Shooting

  1. What is the work-around to "Cannot call BinaryRead after using Request.Form"?

    This error has been caught in version 3 and gives details for working around it. This problem occurs because the Request.BinaryRead method may only be called once. Both the Request.Form and Upload class call this method. You have to make a choice. Do you want to use the Upload class to get your form data, or the standard Request.Form?

    Most people run into this problem because they want to request other data posted on the form besides the file itself. The Upload class does support this. Use the following code to help you out.

    Dim Upload
    Dim Description
    Set Upload = New clsUpload
    Description = Upload("Description").Value
    Set Upload = Nothing
  2. How do I use Request.Form? I get Request object error 'ASP 0207 : 80004005' Cannot use Request.Form

    See: What is the work-around to "Cannot call BinaryRead after using Request.Form"?

  3. What do I do if I get a Microsoft VBScript compilation error '800a0401' Expected end of statement?

    Your web server is not running with the latest version of Microsoft Windows Script. This script has been verified with vbScript version 5.5 and above. Microsoft Windows Script is available free of charge from the Microsoft web site.

    http://www.microsoft.com/scripting - Microsoft Windows Script

  4. My host does not allow the use of the File System Object. What can I do?

    Some web service providers do not allow you to create the Scripting.FileSystemObject object, or they restrict it to have limited functionality. If this is becoming a problem for you, then you can disable this feature. Look in clsUpload.asp for a Const variable named FileSystemObjectEnabled. Set this value to false and you should be ready to go.

    Const FileSystemObjectEnabled = False

    The file system object was used to add new features in this version that allow you to move, copy, delete, and rename files. It also aids in identifying a unique name for the file, and verifies the upload directory exists. It is not required in order to upload files or save them to the file system.

  5. I have error 8000### ?

    If an error isn't addressed within this FAQ, and the error message returned does not help you, then please contact me (lewis@moten.com).

  6. I fixed line ###, what do I do?

    Please contact me with the reason the code was changed and the source code that you updated it with. (lewis@moten.com)

  7. How can I read the raw data of what is actually coming from the user?

    For debugging purposes, I have created a DebugText method that you may use. I advise to use this with small text files, as the time to debug increases according to the amount of data that it has to parse. If you have a browser that is giving you problems, then you can send me the results returned from this method and I can look at the results and determine if I can come up with a solution to your problem.

    Dim Upload
    Set Upload = New clsUpload
    Response.Write Upload.DebugText
    Set Upload = Nothing
  8. My websites host doesn't allow me to use the file system object. What do I need to do?

    Open the clsUpload.asp file and look for the line that assigns a value to FileSystemObjectEnabled.  You will need to set this value to false.  If you disable the file system object, then you will not be able to display progress meters or interact with the file system through the upload class.  However, you will still be able to save files to the file system and/or database.

    Const FileSystemObjectEnabled = False

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.

Virus note:All files are scanned once-a-day by Planet Source Code for viruses,but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:
1)Re-scan downloaded files using your personal virus checker before using it.
2)NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.


Other 100 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/2/2003 2:44:18 AM:Raymond Velasquez
Lewis, you're the best...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/2/2003 3:22:08 AM:Chris Read
Great work!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/2/2003 3:36:36 AM:Chris Read
Just to let you know, the ChiliSoft ASP Package does not support VBScript classes.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/2/2003 9:28:50 AM:Lewis Moten
Thanks for the update Chris. I'll try and update the documentation tonight.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/2/2003 11:26:50 AM:
Thanks for the update! I may have one problem with the progress bar, because in my application I have to keep the track about users while they are uploading files. If I understood well, I can't use the session number in the progress bar page (uploading). I don't know how to link then that file with the particular user. Could you explain it to me, please? You're the best!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/2/2003 3:12:16 PM:mozka
wow, i have ver 1 working like a charm, i'm gonna try this version, great piece of code
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/2/2003 3:35:57 PM:Lewis Moten
Hmm... there is a difference between the upload session id, and the ASP session id. you pass the upload session id to both the progress bar pop-up and the asp page that you are uploading the file to. Please visit the support site and repost your question there so we can communicate easier. http://upload.lewismoten.com
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/4/2003 1:29:35 AM:troubleshootsdotnet
When is VBscript better than PHP? Would the server need to be IIS/Win32? I'm curious on using VBScript. How does this script help VBscript users? Is it basically to avoid having to bug the web admin to install COM packages or something? Thanks all.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/4/2003 2:02:18 AM:
you've outdone yourself, Lewis! Everyone else, don't forget to VOTE for this code if you find it useful! I know I have... now if I can just get the anti-leech downloads working this smooth. :p
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/4/2003 10:59:36 AM:Lewis Moten
I haven't worked with PHP much. I've installed Nuke and created my own template for it (Ivy) http://www.magic-in-a-package.com/nuke, but that is as far as I've gone. Yea - basically you don't have to bug the admin to install a COM component, and you don't have to buy one either. This version of the upload script has introduced the ability to display a progress bar during uploads. So that may help set it apart from most COM components.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/11/2003 12:34:16 PM:Francisco J Riquelme
Good Job! Congratulations! However I have a question: It is possible upload files from remote servers? With your code you just can upload files from your local machine, but what about files from remote servers. Regards,
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/11/2003 12:44:43 PM:Lewis Moten
I'm sure it is possible, however - my code doesn't provide this feature. You may want to look into RFC 1867 to build one and then test it against my script. Don't forget to include the content type when posting files.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/19/2003 12:50:42 PM:
to start, let me congragulate you on your code. It's well written and I learned a lot reading it - I'm more of a database developer than an .asp developer, but I'm learning as I go. Because the .asp code locked up my local install of IIS under WindowsXP Pro, I had to step thru (using Visual InterDev 6 debugger) and figured out what you had done every step of the way. It turns out (and I'm only passing this on in case others have the same problems) that: 1. Norton AV by default kills FSO: http://www.iisfaq.com/default.aspx?View= A387&P=1 2. the ProgressMeter wouldn't update / show until the file transfer was complete. IIS, by default, enables Buffering. Can you use Response.Buffer to disable?
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/26/2003 1:24:27 PM:James (Lycaon)
Sure, you can. Response.Buffer = False
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/7/2003 2:54:32 AM:Serkan GERAY
Is it all? I thought every body know that already ... haha ...
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/7/2003 6:59:15 AM:
am wondering, how do i detect if the user left the file field empty? Cheers Nick
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/22/2003 5:51:56 PM:
This code is fantastic. I have used the previous two versions and it just keeps getting better. Nice work!! If you are looking for suggested for future versions, on the fly image manipulations would be cool (resampling/resizing, greyscale, etc)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.