Important alert: (current site time 4/24/2014 9:16:34 AM EDT)
 

article

Upload Files Without COM v3

Email
Submitted on: 9/1/2003 11:19:59 PM
By: Lewis E. Moten III  
Level: Advanced
User Rating: By 56 Users
Compatibility: ASP (Active Server Pages)
Views: 122671
author picture
(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 102 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

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 AMRaymond Velasquez

Lewis, you're the best...
(If this comment was disrespectful, please report it.)

 
9/2/2003 3:22:08 AMChris Read

Great work!
(If this comment was disrespectful, please report it.)

 
9/2/2003 3:36:36 AMChris Read

Just to let you know, the ChiliSoft ASP Package does not support VBScript classes.
(If this comment was disrespectful, please report it.)

 
9/2/2003 9:28:50 AMLewis Moten

Thanks for the update Chris. I'll try and update the documentation tonight.
(If this comment was disrespectful, please report it.)

 
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!
(If this comment was disrespectful, please report it.)

 
9/2/2003 3:12:16 PMmozka

wow, i have ver 1 working like a charm, i'm gonna try this version, great piece of code
(If this comment was disrespectful, please report it.)

 
9/2/2003 3:35:57 PMLewis 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
(If this comment was disrespectful, please report it.)

 
9/4/2003 1:29:35 AMtroubleshootsdotnet

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.
(If this comment was disrespectful, please report it.)

 
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
(If this comment was disrespectful, please report it.)

 
9/4/2003 10:59:36 AMLewis 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.

(If this comment was disrespectful, please report it.)

 
9/11/2003 12:34:16 PMFrancisco 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,
(If this comment was disrespectful, please report it.)

 
9/11/2003 12:44:43 PMLewis 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.
(If this comment was disrespectful, please report it.)

 
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?

(If this comment was disrespectful, please report it.)

 
9/26/2003 1:24:27 PMJames (Lycaon)

Sure, you can.

Response.Buffer = False
(If this comment was disrespectful, please report it.)

 
10/7/2003 2:54:32 AMSerkan GERAY

Is it all? I thought every body know that already ... haha ...
(If this comment was disrespectful, please report it.)

 
10/7/2003 6:59:15 AM

am wondering, how do i detect if the user left the file field empty?

Cheers

Nick
(If this comment was disrespectful, please report it.)

 
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)
(If this comment was disrespectful, please report it.)

 
11/28/2003 8:50:25 PMherleybird

un COM Man!!!
Can you show how to adapt VB auto upload @
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=6076&lngWId=4
(If this comment was disrespectful, please report it.)

 
11/28/2003 8:55:18 PMherleybird

Try again....un COM Man!!! Can you show how to adapt VB auto upload @
http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6076&lngWId=4
(If this comment was disrespectful, please report it.)

 
11/28/2003 8:57:03 PMherleybird

ok it auto places space in?
...lngW Id=4
remove it and then link works
(If this comment was disrespectful, please report it.)

 
12/10/2003 1:30:48 AM

i need to do this .

Upload(replace(Request.Form("testimonial1"), "'", "''")).value

a replace but how can i conbine it woth your code.

cheers aron.
(If this comment was disrespectful, please report it.)

 
12/12/2003 3:42:29 PMmystiphire

I would love to see this work with macintosh users, freeaspupload.com works with macintosh users maybe you can find out why looking at their source code and implement it into yours. Just a thought.
(If this comment was disrespectful, please report it.)

 
12/17/2003 11:56:40 PM

Woo woo these are fun!
I combined unique_save and restrict_save with a random string generator to get an upload that gives all uploaded files a randomly generated name. What is good about this is when you have a community site that non-technies upload images to, they usually have bad filenames with spaces and special characters in them. This script combo bypasses that problem completely.
(If this comment was disrespectful, please report it.)

 
1/16/2004 2:17:40 PM

The values from form fields, such as:
objUpload.Fields("firstName").Value all seem to include a trailing vbCrLf (CarriageReturn - LineFeed). Is this by design, or is there a way around this other than using 'Replace(firstName,vbCrLf,"")' everytime I grab a value?
(If this comment was disrespectful, please report it.)

 
1/26/2004 8:34:21 PM

How do I know if the file they type in exists on their system? They way it is now, I can type anything into the file field and according to the progress window, it uploads about 200 bytes of nothing!?
(If this comment was disrespectful, please report it.)

 
2/6/2004 10:17:56 AM

Hi Lewis Moten,
Thanks for your code.It seems the string returned by for example Upload("type").value adds extra 2 characters(space & may be some terminating one)at end of form value. Because of that the string equality test fails(e.g: If Upload("type").value = "sedan"). So I had to remove those 2 extra chars at the end to make the test success. Can you correct this in your next release.
Thanks
(If this comment was disrespectful, please report it.)

 
2/25/2004 9:40:51 AM

Hi,

Your code is executing fine, without giving any error and also geting the message "File has been saved to file system. ". But, actually file has not been uploaded. Could any body please suggest me what might have gone wrong or where I'm making mistake.

Thanks and regards,

Naresh
(If this comment was disrespectful, please report it.)

 
3/17/2004 6:02:52 PM

It works great. I am having problem on one of my servers. I have three servers running 2000 and it works ok on two but for some reason, the progress bar does not show on one of the server. The status opens and it says please wait ... and thats it. Any suggestions...
Thanks,
imohammed786@hotmail.com
(If this comment was disrespectful, please report it.)

 
5/9/2004 11:36:17 PM

give same example purchasing system file or coding of VB
(If this comment was disrespectful, please report it.)

 
5/20/2004 3:51:04 AM

Can you support double character file name upload?

Thank you.
(If this comment was disrespectful, please report it.)

 
6/4/2004 5:49:52 AM

Hi Lewis,

I used your code to upload files which is working absolutely fine in Windows 200 operating system but not in windows 98. Could you please suggest what should I do to resolve that problem.

Regards,
Debasis
(If this comment was disrespectful, please report it.)

 
6/4/2004 8:42:22 AMLewis Moten

I believe it uses ado 2.7. (It's been a while since I looked at it). Try posting what the problem that you are having is and make sure you have the latest MDAC/ADO components.
(If this comment was disrespectful, please report it.)

 
6/6/2004 10:15:04 AM

Hi Lewis,

I believe MDAC/ADO are required on the server side not on the client side. What if the data is not getting transmitted to the server. Is there any possibility that data will not be sent to the server from windows 98 pc using multipart/ enc type.

Regards,
Debasis
(If this comment was disrespectful, please report it.)

 
6/23/2004 10:02:53 PM

Hi Lewis,
Thanks for your code, it works beautifully. FYI - There is one small issue I had when using Uploader("fieldname").Value for text input fields and Uploader.Collection("fieldnames") for the select statements - it was inserting carriage returns at the end ie chr(13)+chr(10).
It was causing an error with the select boxes so I just trimmed these off and it works fine now.
(If this comment was disrespectful, please report it.)

 
6/23/2004 10:26:24 PMLewis Moten

I got an email from someone else with a problem and it turned out to be the same thing. You wouldn't happen to be Mark would you? I'll be re-posting the code shortly if the fix is confirmed. (clsUpload.asp line 337 - change 2 to 4)
(If this comment was disrespectful, please report it.)

 
8/4/2004 2:39:09 PM

code works great!!! I've uploaded an image to an Access db and now I want to email the image. Not sure how to retrieve it and send an email. I'm able to retrieve it and display it in the browser. Any tips?
(If this comment was disrespectful, please report it.)

 
8/4/2004 9:32:32 PMLewis Moten

You can always pull it rite back out of the database and save it to the file system. You could also do both when the original file is uploaded. You would need to use an email COM object that supports file attachments and point it to the physical location on the hard disk.
(If this comment was disrespectful, please report it.)

 
8/5/2004 8:56:46 PMLewis Moten

Files have been updated to remove the vbCrLf characters from the field values.
(If this comment was disrespectful, please report it.)

 
8/10/2004 10:31:35 AM

Hi Lewis, I am using your file upload class to upload an image to the filesystem. I was just wondering if there is anyway with you Image class that the file can be resized to a certain width (that I set) but the height of the file is worked out according to what the width is.. Aspect ratio in other words?
(If this comment was disrespectful, please report it.)

 
8/18/2004 2:04:54 PMMichael L. Canejo

Hello Lewis, I have been around PSC for about five years now.. I'm glad there are still people willing make nice contributions like this, it is well appreciated!

And now the problem I have, and alot of upload scripts for that matter. Your file restriction methods "work" but there is a problem with the methods used, for my situation. See your upload script actually uploads the data .. processes it .. then checks the size and file extension to restrict saving it to the harddrive.

Continued below....
(If this comment was disrespectful, please report it.)

 
8/18/2004 2:05:41 PMMichael L. Canejo

Now, for my server.. it needs to only allow uploads of 300KB for .jpg file formats.. if a visitor were to upload his 100mb .zip file to my server, it would use so much bandwidth and resources processing this 100mb file just to figure out _after_ that it is the wrong file format and size allowed.

Is there a way to use these file restrictions _ahead_ of time before calling the RequestData sub routine which processes the data to the server? I tried modifying your clsUpload to check the Request.TotalBytes first then exit the script, this yields file not found to the browser... I'm not sure how to conquer this obviously, perhaps you can give some insight.

Kind Regards,
Michael L. Canejo
(If this comment was disrespectful, please report it.)

 
8/30/2004 4:39:43 PM

I'm puzzled while trying to use V2 of this code (before I saw V3). I was able to upload all files in my development server, but are unable to save PDF or TIF files once I moved the codes to production. It doesn't save the file, but it gave no error. Please advice?
(If this comment was disrespectful, please report it.)

 
8/30/2004 6:56:22 PM

I'm puzzled while trying to use V2 of this code (before I saw V3). I was able to upload all files in my development server, but are unable to save PDF or TIF files once I moved the codes to production. It doesn't save the file, but it gave no error.

The difference is that production is Win2003 Server and Dev is Win2000 Server. Please advice?
(If this comment was disrespectful, please report it.)

 
9/1/2004 12:31:25 PM

I tested your code with 50 mb size. IE 6.0 took about 11 minutes and Netscape 7.1 took about less than 40 seconds. That's a big difference. I wonder why this is so? Thanks
(If this comment was disrespectful, please report it.)

 
9/1/2004 9:04:30 PMLewis Moten

All browsers use the same RFC spec. This code doesn't really sniff out different browsers. The difference could be due to network traffic or the amount of CPU/Memory available to the server at the time of your upload. I would suggest more tests if you are benchmarking the script.
(If this comment was disrespectful, please report it.)

 
9/1/2004 9:06:57 PMLewis Moten

Haven't tested with windows 2003, but I do know that it has more security features locked down with a default installation. perhaps the mime type isn't associated with TIF and PDF images on the server?
(If this comment was disrespectful, please report it.)

 
9/9/2004 1:25:03 AMMichael L. Canejo

Thanks for your
(If this comment was disrespectful, please report it.)

 
9/9/2004 1:31:45 AMMichael L. Canejo

Thanks for your ''reponse'' Lewis, could have just said you don't know how or point me in the right direction.

Or perhaps it isn't even possible because of limitations.

I'm sure you know better than I and I'm sure my question is valid enough for any type of reponse.

take care
(If this comment was disrespectful, please report it.)

 
9/9/2004 8:49:18 AMLewis Moten

Michael, I believe that ther is a Request.TotalBytes (or something simular) that you can check before instantiating the upload script.
(If this comment was disrespectful, please report it.)

 
9/18/2004 6:22:20 AM

Hi Lewis. Fantastic Coding. Well worthy of your contest winner award.
One quick question.
I'm trying to use these lines on my local IIS setup...

oldf = Folder & Filename
newf = "new.jpg"
Upload("File1").SaveAs oldf
Upload.RenameFile oldf, newf

But it hangs. And floods my IIS server with 'too many users', but if I remove the RenameFile line it works fine.
Is this because its trying to rename the file when the previous command hasnt finished uploading it yet?
Or could it be something to do with my security - in that it allows uploads but not renaming?
Any advice would be greatly appreciated.

(If this comment was disrespectful, please report it.)

 
9/18/2004 6:25:49 AM

curses! it didnt put any line breaks in! ok, let me try some html breaks! heres those lines again...

oldf = Folder & Filename
newf = "new.jpg"
Upload("File1").SaveAs oldf
Upload.RenameFile oldf, newf
(If this comment was disrespectful, please report it.)

 
9/23/2004 10:23:40 AMMark Kahn

the ADO call at the top of the clsUpload.asp file is causing a variable redefinition error on our servers, presumably in confilct with the const variables in adovbs.inc. I was wondering if you knew of a solution to this, thx.
(If this comment was disrespectful, please report it.)

 
9/25/2004 12:34:19 PM

Upload w/o COM v3 worked OK with Apache 1.331 and Chilisoft/SunOne ASP 4.0 on Win XP Pro SP2. As per the instructions on the SunOne website, I inserted a #include line at the top of clsField.asp: having defined a separate includes directory for the VB stuff in Apache, by inserting the following in httpd.conf: Alias /VBIncludes/ "C:/Program Files/Apache Group/Apache/VBIncludes/" The file adovbs.inc comes from C:\Program Files\Common\ado\, and I put it in the above named directory which I created. I think the ADOVBS.inc file is created by installing IE or IIS on the server, which I did ages ago (I never use them apart from this!) but I see you can download this file from the web as well. After that all seems to run OK (at least the example works, I have not played further for now). Excellent job Lewis.
(If this comment was disrespectful, please report it.)

 
10/19/2004 4:31:22 AM

Here is an addendum to clsField.asp that will allow you to enter data into Oracle database:

Public Property Get BinaryOracle()
Dim rawdata
rawdata = BinaryData
BinaryOracle = ASCII2Bytes(rawdata)
End Property

Use BinaryOracle property to get data for entering into Oracle database instead of BinaryData or BLOB.
(If this comment was disrespectful, please report it.)

 
11/9/2004 8:18:05 PM

It works on Western encoding set, but faild on 2-Byte code encoding like EUC_KR or SJIS. no filename obtained from object. Is there any solution?
(If this comment was disrespectful, please report it.)

 
12/4/2004 1:06:26 PM

I just rated this as Excellent. Thanks Lewis for such a great program. I hopped over from the Jacob Gilley project. I'm one of those who had to up the ScriptTimeout to 3600 to get 150K files to finish uploading. I'm about to implement the progress bar so I can get upload feedback, but am curious why it can take a minute or two on just 150K files.
(If this comment was disrespectful, please report it.)

 
12/24/2004 9:49:50 AM

very good, i'm very interesting in your code. It work well. However, could you consider to add some security check to your code. I asked that because I think it may have some way to use http post to abuse website use these scripts with no change. For example some one can insert an SQL injection into querytring fileID in database_download.asp. Some prying people can use http post to upload anyfile to webserver thru database_save.asp. Are these threats true. If they are, please let me know. Finally, I rated this scripts as excellent and asked you to add this code to my non-commercial web application for my school (with credit lines left AS-IS). Sorry for my English. To me you are the most favourite coder in ASP. Happy chirstmas, man.
(If this comment was disrespectful, please report it.)

 
1/9/2005 8:38:02 PM

This is great code, thanks for everything
(If this comment was disrespectful, please report it.)

 
1/17/2005 9:05:39 AM

I get this error when I try to upload:

Upload Without COM (0x80040004)
Failed to save file: 2005_Jan_17-31765.34.bin. No data was found within the file (zero bytes). [Need help? Contact Lewis Moten, lewis@moten.com, http://www.lewismoten.com]
/admin/upload/clsField.asp, line 248

I'm not sure how to troubleshoot this one. Any help would be appreciated. Btw, this is a great piece code despite my issues. Thanks.

(If this comment was disrespectful, please report it.)

 
1/26/2005 10:37:05 AM

I have eactly the same issue as the one mentioned above...any help please?!


(If this comment was disrespectful, please report it.)

 
1/29/2005 2:23:54 AM

asdasd
(If this comment was disrespectful, please report it.)

 
1/29/2005 2:31:09 AM

Id like to make the image upload portion of my web form optional. It appears that the ToFileSystem.asp page is expecting a value.

Ive tried this...

if objUpload.Fields("File1").Length = 0 then
strFileName = "noimage.jpg"
else
strFileName = objUpload.Fields("File1").FileName
end if

But it doesnt work. PLEASE HELP!

John
(If this comment was disrespectful, please report it.)

 
1/29/2005 4:53:08 AM

Lewis can you help with the request above please?
(If this comment was disrespectful, please report it.)

 
1/30/2005 2:26:34 AM

mate im desperate...could you help out?
(If this comment was disrespectful, please report it.)

 
2/14/2005 10:27:43 AM

I was previously using version 2.0 of this great code - moved to version 3.0 - and I've run into a problem. I have a form with multiple documents (optional). Before I would check the filename of the uploaded document and if it was not empty I would attempt to process it (i.e. Upload("doc").FileName <> ""). Now, that check is not working because the filename (when no document was attached) is showing up as something like 2005_Feb_14-37571.93.bin - how can you tell with version 3.0 if a file was provided or not??
(If this comment was disrespectful, please report it.)

 
2/18/2005 12:10:03 PM

I haven't had a chance to test this yet becuase the I'm having a conflict with my CMS. I get the error:
Name redefined: 'adOpenForwardOnly'

Whenever I include the upload class in my script, which has this variable defined. I haven't been able to find
(If this comment was disrespectful, please report it.)

 
2/18/2005 12:13:21 PM

'adOpenForwardOnly' in the scripts anywhere, which leads me to beleive that its perhaps somewhere in the COM? Why would these conflict I'm not sure but if anyone has a work around please post! (Hopefully I won't have to remove the ADO constants from my code)
(If this comment was disrespectful, please report it.)

 
2/18/2005 5:15:54 PM

nevermind I found the ado include... now I'm getting the same error as the poster above: No data was found within the file (zero bytes)

bleh.
(If this comment was disrespectful, please report it.)

 
2/18/2005 7:47:53 PM

FYI: I fixed my issue by adding these to my ado constants: Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
Const adModeReadWrite = 3
Const adPromptNever = 4
Const adLongVarBinary = 205
Const adVarChar = 200
Const adLongVarChar = 201
Const adReadAll = -1
Seems to be working great now!
(If this comment was disrespectful, please report it.)

 
3/2/2005 11:13:32 AM

for those having troubles with your old codes of using .filename to check for whether a file is specified for uploading, the version 3 just change to upload("file1").length>0
(If this comment was disrespectful, please report it.)

 
3/15/2005 10:28:56 AM

Microsoft VBScript-runtime error '800a000d'

Type mismatch: 'CDbl'

/upload/examples/clsUpload.asp, line 1052
What's wrong here?
(If this comment was disrespectful, please report it.)

 
4/1/2005 11:23:34 PM

Hi, Lewis many thanks for your code, I'm executing the 2Files_Form.htm code and after entering the two files I want to updload, I'm getting a message
(If this comment was disrespectful, please report it.)

 
4/1/2005 11:31:39 PM

Hi, Lewis many thanks for your code, I'm executing the 2Files_Form.htm code and after entering the two files I want to updload, I'm getting a message message "File has been saved to file system". When I then click on the two links I get errror meesages stating that files does not exist. If I also go to the directory no files were created
(If this comment was disrespectful, please report it.)

 
4/6/2005 12:13:16 PMMark Kahn

I was recently forced to come up with a solution to the confict issue between upload objects (any upload object, not just yours) and the request.form. Thought you might be interested in the solution: override the request object. Yep, replace it with your own class. If you're interested in the exact details (and code), e-mail me. It's too long to paste in here (and plus all the line breaks, etc die).
(If this comment was disrespectful, please report it.)

 
4/7/2005 3:29:26 PM

I've tried using this code in place of the existing upload code we currently use, however I am still finding it to be very slow. I set the Buffer Size to 256KB, but it still took 1 min, 39 seconds to upload a 144KB file. Is this common? Would the type of file being uploaded impact the speed? The file I tested with was a PowerPoint file. I imagine a file closer to 1 MB would cause timeout issues...is there any way to speed this up further?
(If this comment was disrespectful, please report it.)

 
4/10/2005 5:06:38 PM

Solution for :No data was found within the file (zero bytes).
Change :
Upload("File1").SaveAs Folder & FileName1
To : if upload("file3").length>0 then Upload("File1").SaveAs Folder & FileName1

I also in the default naming in clsUpload.asp(Line 643) to set the default name to "blank.gif"

I upload 4 files and set the if statemnt for each , this way the user can upload 1 ,2,3 or 4 files , by leaving the input blank of the ones not to be uploaded.
Excellent code !!! Excellent progress bar !!! thank you for making this available freely !
(If this comment was disrespectful, please report it.)

 
4/25/2005 4:33:43 PM

I have attempted to set up your scripts as instructed. The upload seems to execute, and there are no error messages. However the jpgs I am attempting to upload are not being stored
(If this comment was disrespectful, please report it.)

 
4/25/2005 8:34:40 PM

Never mind, solved the problem. The permissions on folder needed to be changed. Your code works great, but I assumed there was an error message in case the file failed to store in the folder.
(If this comment was disrespectful, please report it.)

 
4/26/2005 8:46:11 PM

Great code, but having difficulting understanding it. Can anyone direct me towards resources that might help? For example, would studying scripting objects help?
(If this comment was disrespectful, please report it.)

 
5/3/2005 2:42:21 PMMark Kahn

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=9123&lngWId=4

use
that instead of string concatenation in the CStrU and CStrB functions.
(If this comment was disrespectful, please report it.)

 
6/1/2005 2:51:53 PM

i can only said you are a master.
Did you tried to use this code with oracle database? Please help
Thanks
(If this comment was disrespectful, please report it.)

 
6/7/2005 6:02:06 PM

Thousands of people have downloaded the code and only 38 rated the article, please show some support! BTW Lewis, the examples worked like a charm. I was experiencing some trouble with v2 and different browsers, especially attempting to retrieve the files from the database. I'll let you know after I try them exhaustively with SQLServer2000. Great work.
(If this comment was disrespectful, please report it.)

 
6/29/2005 10:55:13 PM

On my ASP system, the only way I can get UFWCv3 to work is to set IUSER_nnnn to permit R/W at the root. I've tried setting this user at lower levels, to no effect. I get the following error:

Microsoft VBScript runtime (0x800A0046)
Permission denied
/cgi-bin/comments/clsField.asp, line 227

The 227 line is this:
AvailableSpace = FSO.GetDrive(Drive).AvailableSpace

The results are independent of browser or file size or even presence of a value in the FILE1 field. Thanks for any suggestions.
(If this comment was disrespectful, please report it.)

 
8/17/2005 2:28:10 PM

Great code!! I am new to vbscript and this code was very helpful to me. Thanks
(If this comment was disrespectful, please report it.)

 
9/20/2005 1:46:41 PMChris Ewin

The clsImage Class only detects JFIF Formatted JPEG Files and does not recognize Exif Formatted JPEG's which is used by many digital cameras.
(If this comment was disrespectful, please report it.)

 
10/7/2005 4:22:18 PMLong

Just stumbled onto this by accident while search for ways to upload via html/asp scripts. Just want to drop a line and say hi as well as thank you for all the hard work you put into this. It being free is just icing on the cake for me.
(If this comment was disrespectful, please report it.)

 
10/10/2005 2:17:50 PMLong

Just curious, has anyone been able to upload to a remote server? I know that Moten's does not support this. I went and read the article but do not have a clue as to how to solve this.
(If this comment was disrespectful, please report it.)

 
10/17/2005 12:26:23 AMalex@yoshida-family.com

After spending several agonying, unsuccessful days to make Japanese file names (double-byte non-unicode character set, shift-jis) work, I gave up.
But, I have a solution.
1. In FORM, add onSubmit to a JavaScript function where the TYPE=FILE field (File1, File2...) values are stored to a cookie.
2. In the following ASP (actual UPLOAD execution) page, and at its beginning before UPLOAD process is started, retrieve the cookie just saved in the previous page, using VBSCRIPT function
such as
LocalFileName=Request.Cookies("File1")
3. When saving the uploaded file on the server, use this cookie value (in this example, LocalFileName) instead of the value Upload("File1").FileName

This approach finally worked fine with a file with the double-byte Japanese file name.
(If this comment was disrespectful, please report it.)

 
10/22/2005 9:09:26 PMKerry Mott

This may sound dumb but how do I map the path to the remote server? I followed the instructions and the files were successfully transfered from the form when I placed the upload folder in the same directory as the the other web files. Thanks for your help...
(If this comment was disrespectful, please report it.)

 
10/24/2005 6:33:23 AMKerry Mott

Disregard above message..the problem was solved by setting FileSystemObjectEnabled = False in file ClsUpload.asp as suggested, seems to be working fine..great work!

(If this comment was disrespectful, please report it.)

 
11/1/2005 5:38:25 PMMike

I have been using this ASP upload for a long time now. It recently broke after we migrated to Server 2003. It seems we can upload files to the database but can only read files of .XLS content type. The others just forward to a page not found error. Also, older files in the database (before the migration) can be read of any type. Can anyone help me shed some light on this???
(If this comment was disrespectful, please report it.)

 
11/25/2005 9:00:52 PMHipnoart

THis is a great piece of code.
Just a quick question, I have 3 file fields to upload upto 3 images (works like a charm) but when I decide NOT to upload a 2nd or 3rd file it throws a datasize error, anyway around this?
I´ve tried ifs but it only hangs.
THanks again for a great code
(If this comment was disrespectful, please report it.)

 
12/26/2005 11:12:03 PMMark B

Kickass code .. but I'm having problems.

It seems when I go and try to execute via the FckEditor's Image Upload feature, I loose the ability to do any string manipulation. This means when I call Server.MapPath I can't add another \ to the end OR can I pull oUploader.Fields("NewFile").FileName without the script crashing.

See .. This works when I just do this from a webpage, but I can't make it work from FckEditor. Really stumped.
(If this comment was disrespectful, please report it.)

 
1/3/2006 3:18:27 AMchris

hi,
thnx for ur code... it works well except with big files. if i try with files bigger than 2 mb then it's giving problem. I think before uploading the entire contents it finishes the job telling files uploaded.
Could you pls, tell me the way to sort it out?...
thnx in advance.
(If this comment was disrespectful, please report it.)

 
1/11/2006 8:16:10 AMMichael McCorry

Awesome script, however I've come across a problem where the file finishes uploading fine according to the progress window, yet the main window does not immediately click over to the next page. It hangs there like it's still uploading. EVENTUALLY the page loads fine, but this can take many minutes.

The servers affected are Win 2003/XP & IIS. The length of pause after the file is uploaded is longer depending on the size of the file (usually files over 200K). I tried uploading a 1MB file. It uploads fine according to the progress win, but had to wait over 10 minutes after it had finished before the page clicked over. During this time, overall server performance seems to slow right down until it's finished doing what it's doing. Adjusting the BufferSize doesn't make any difference.

If you have any wisdom you can share, it would be very much appreciated, as this has me stumped.
(If this comment was disrespectful, please report it.)

 
1/15/2006 4:04:21 PMInternet Resource Solutions

Awesome code. I was wondering though. you have clsImage, is there a way to resize an image using this?
(If this comment was disrespectful, please report it.)

 
2/9/2006 4:12:11 PMDenis J. Lanza

Hey Lewis,
Incredible code man! It really saved my butt at work. I actually rewrote the entire application in C# for use in an ASP.NET Web App. If anyone is interested, let me know.

Denis
(If this comment was disrespectful, please report it.)

 
3/12/2006 10:09:59 PMAeric

Great code. May i know how i can save the filename to the database after i have uploaded the file to file system? Thanks.
(If this comment was disrespectful, please report it.)

 
3/13/2006 8:20:14 PMAeric

Oh, i solved my problem. It is related to Troubleshooting no. 1
(If this comment was disrespectful, please report it.)

 
3/23/2006 3:24:43 AMmyhazil

you are superm!!
(If this comment was disrespectful, please report it.)

 
3/23/2006 3:25:04 AMmyhazil

you are superm
(If this comment was disrespectful, please report it.)

 
6/1/2006 6:25:17 AMErica

Hi, I just downloaded your code for uploading images with Asp. It’s brilliant! Thank you very much!!



Was just wondering if it was possible to upload 4 images at a time and still make the names unique if they have been uploaded before?



This is wwhat I have at the moment but it does not seem to make the image names unique:



Folder = Server.MapPath("Uploads") & "\"

FileName = Upload.UniqueName(Folder, FileName)

Upload("Image1").SaveAs Folder & Upload("Image1").FileName

Upload("Image2").SaveAs Folder & Upload("Image2").FileName

Upload("Image3").SaveAs Folder & Upload("Image3").FileName

Upload("Image4").SaveAs Folder & Upload("Image4").FileName





Thanks very much!

Erica Waters

(If this comment was disrespectful, please report it.)

 
8/3/2006 3:09:38 PMmartin

Hey Lewis, this version's a winner, and it's so much easier for a newb like me to tweak.

It works beautifully with images but having problems with audio files. It seems to upload as normal (15-20 mins on the main page, 128 upload speed), but then instead of redirecting it just hangs a white window for about 10 mins. Then I get "specify encType as multipart-form data" error in clsUpload (line 936). It is specified as that btw.

They're large files... I'm trying to upload 2 x mp3 and 1 x Zip files (40 megs total) from the same page.

Is there any way round this or is 40 megs just too ambitious?

Thanks in advance for any help - even if I can't get this working it will still have helped me out many times over. All the best, Martin
(If this comment was disrespectful, please report it.)

 
8/3/2006 4:10:50 PMmartin

sorry if that was unclear. I have specified the form as multipart/form-data. But the error message still comes up. Thanks again.
(If this comment was disrespectful, please report it.)

 
8/4/2006 9:54:30 PMmartin

well it's a shame I couldn't manage the 40 mb uploads - but I'm good with a couple of 20 megs. Thanks again for the code Lewis. Much much appreciated.
(If this comment was disrespectful, please report it.)

 
8/8/2006 9:21:19 PMYasir

Hi Lewis, many thanks for a great code that helped me and i'm sure a lot of people.
I've managed to work fine with all of your code. But the problem i'm facing is being able to upload the image and save the data into the database. I have used the data you have provided above in your website, but I get the following error message:

Microsoft VBScript runtime error '800a01a8'

Object required: 'objUpload'

/upload/Upload.asp, line 15

I've just got into ASP coding, so I'm finding it difficult to solve this error.

Hope you can help me.
Thanks.
(If this comment was disrespectful, please report it.)

 
8/16/2006 2:44:14 PMpsicoz

perfect
(If this comment was disrespectful, please report it.)

 
8/31/2006 8:20:51 PMtelis

Dear Lewis,
[respond to: telis a/t evresis dot com dot cy]
I have been playing around with the “Upload Files Without COM v3” object you created.
I think I have found a which seems to appear when the IUSR is not allowed to save into the upload folder.
Specifically – clsField.asp line 286 & 295.
For some reason, your PublishError subroutine, although it calls “On Error Goto 0”, this does not take effect (maybe because it is specified in the subroutine context?).
Solution is addition of “On Error Goto 0” just before calling PublishError.
These are just the ones I came across, and I believe there are no other similar probs.
I hope it is OK to modify your program for this purpose or maybe you can provide an updated version online so that all benefit.
If you do, please let me know where to get it from.

Thanks

PS. Good job. Also, your emails are all wrong.
(If this comment was disrespectful, please report it.)

 
12/16/2006 1:23:51 PMcomments!!!

great work dude, this is simply the best, but if i want to resample my image while uploading how to do ? can you help.
(If this comment was disrespectful, please report it.)

 
12/22/2006 2:40:55 AMSmart Peter Mak

I have seen your code since v2, however, I just discovered that there is a v3!!!

Really a good work! Excellent! and all your work push me here to says thanks for your code.

After reading this feedback list and tried your code, I summarize the following common-faced-issues:

1. failed to upload file with double byte file name. as suggested by alex@yoshida-family.com, using javascript cookies is one of the way. however, I still have no luck to do it successfully... I'm keep trying... seems due to encoding problem...
2. unable to resize image (as far as i know, vb script never provided this feature. only a customized DLL will work...)
3. file size checking after uploaded is a bit depress to the user, will Request.TotalByte work well? I am going to try...
4. Upload("field").Value isnt work well in double byte text also... I am still figuring it out..

anyway, good work!!
(If this comment was disrespectful, please report it.)

 
12/30/2006 11:13:55 PMJohn

Gday Lewis,
Firstly as already pointed out by many other members here - this code is absolutely fantastic. I had it up and running within a few minutes without any issues.

I have one question however. I am wanting to allow file types of "MPEG" and "MOV" to be uploaded to the system. The files upload ok but display as "BAD IMAGE" as i suspect an image is expected rather than a media file.

Is there a current solution to this?

Thanks mate,
John
(If this comment was disrespectful, please report it.)

 
2/14/2007 11:07:10 PMkob

Wonderful code. easy edit work great with folder and binary , clearly my problem 5 point for u.
(If this comment was disrespectful, please report it.)

 
3/1/2007 11:23:09 AMRogger

Congratulations !!!, this is a wonderful . but I have a question can I upload a file but the content recide in buffer???
Sorry for my English

(If this comment was disrespectful, please report it.)

 
4/5/2007 12:49:36 PMmeir

i try to do the "1.How do I install the scripts?" to upload files, i folow after the instraction and it's not working.
i copy the files to my folder and not work.
(If this comment was disrespectful, please report it.)

 
5/14/2007 4:42:34 PMBeth

Thank you for this valuable tool, Lewis! I got it up and running without too much difficulty, but when I try to upload an invalid file using Internet Explorer 7 (i.e. one that doesn't exist) it seems to hang on the Submit button and never goes to the Upload.asp code where I check for validity. It works fine in Mozilla. Any ideas?

Thanks!
Beth from California
(If this comment was disrespectful, please report it.)

 
6/5/2007 9:10:06 AMJohn

Hi Lewis,
Mate I'm having a little trouble with your code. The thumbnails and images are uploading to the site ok, but they are simply taking far too long to display on screen as many users are uploading 1MB+ files. I really dont like the idea of prompting them to resize their images as most end users wouldnt know how to do this.

Whilst I am considering different code is there a way of calling the thumbnails with a smaller size or automatically resizing the images on the fly???

Could you please help me out Lewis? Im stuck here and have a rather annoyed client!

You can see the issue here on this site www.ozrvsales.com.au - the images take forever to display

Ideally I would like to allow ANY image size to be uploaded then automatically resize the image when displayed in the thumbnails etc on screen

Thanks,
John
(If this comment was disrespectful, please report it.)

 
6/5/2007 11:56:23 AMJohn

This script whilst good desperately needs some form of image autoresize before or during upload.

Its unnacceptable to watch 1MB thumbnails loading - especially when you might have 10 of them onscreen over a 42K dial up connection!!!

Please address this Lewis!

John
(If this comment was disrespectful, please report it.)

 
6/5/2007 1:37:41 PMJohn

Is there a way of calling the thumbnails at a lower file size? At the moment Ive got thumbnails at ...

182999 bytes
719241 bytes
259812 bytes

They take forever to load!

Ideally these should be down in and around 2000 bytes!

Is this possible Lewis - please advise!

Thank you,
John
(If this comment was disrespectful, please report it.)

 
6/11/2007 12:20:17 PMPete

Thanks for the awesome script, but I'm getting an occasional error in our logs, and I'm trying to track down why. I'm getting an error on line 191 in clsProgress.asp, saying "Bad file name or number.". The IIS logs show it as the following two lines:

GET /Progress_Status.asp Session=6b0e2 200 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322;+InfoPath.1)
POST
/ToFileSystem.asp Session=219824?Session=6b0e2|191|800a0034|Bad_file_name_or_number 500 Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+1.1.4322;+InfoPath.1)
I
can't seem to figure out *why* the file name might be bad, though. I was hoping maybe you had some idea on a common way this error might be generated? Thanks for any help, and thanks for the awesome script!
(If this comment was disrespectful, please report it.)

 
7/14/2007 5:43:52 PM

This is an excellent script - thank you!

Has anyone figured out a way to setup the multiple file upload routine (file1, file2, file3) but not have it error out if only one file is uploaded?

Right now, if you have it setup for a 3 file upload and only select one file, it throws a save error for the other two files saying they are zero byte size.

If you could post a solution here that would be wonderful! Thank you!
(If this comment was disrespectful, please report it.)

 
7/15/2007 12:16:16 PMmrkaroshi

Got problem with clsUpload v3.

I have a form which allows up to 3 files to be selected. If I select 1 (a small text file) and submit it … on the receiving end, I then receive not just one file, but 3 (THREE) files. One of them is the one I expected,

But the other two are named 2007_Jul_15-40295.27.bin … though the contents of these appear to be not binary, but the same as the text file I submitted.

Any idea what is going on here ???


(If this comment was disrespectful, please report it.)

 
7/23/2007 4:49:47 PMtesfa

I must say good work on this project...its quite good..however i'm having a problem uploading pdf documents i'm not quite sure why...i'm still trying to debug....
the error points to this line
lnBytes = Request.BinaryRead(lnByteCount)...
any ideas??.....

(If this comment was disrespectful, please report it.)

 
10/26/2007 4:41:20 AMWill

I recently downloaded your ASP Upload V3. It works perfect on my PC. But
when I tried to upload file on my friend's laptop, the ASP code can not read the binary data. It took me a few days to find out the problem. I went to IE Tools, Advanced and Reset the browser. It worked. I did not know which setting caused this problem. Can you let me know if there's an easy way to enable browser sending binary data?


(If this comment was disrespectful, please report it.)

 
11/8/2007 1:27:55 PMnicola

I love your work, thanks.
Is there a way I can resize my images on Upload, for example: if height > width then set height to .. else set width to ..and perhaps also set the resolution?
Thanks for any help you can offer.
(If this comment was disrespectful, please report it.)

 
11/24/2007 10:17:03 AMJohn

Ive been using this code for some time now and have firstly one question...

1. How is it possible to prevent people uploading renamed exe files as images and...

2. This code simply MUST be used in conjunction with a resizing component such as ASPJPEG. Throwing 1MB thumbnails to screen is simply innefficient!!!

John
(If this comment was disrespectful, please report it.)

 
1/7/2008 12:58:09 PMRJ

I can not get the original path back in Firefox

response.write Upload("File1").FileDir will show
\\Bur-na-fs01\dts\DailyDataPulls\Alchemy\US in IE but nothing in firefox

this line
Upload("File1").SaveAs Folder & right(Upload("File1").FileDir,2) & Upload("File1").FileName

works fine in IE and adds our market ID to the saved filename but not in firefox which does not seem to be able to get the directory info

Anyone know how to get this to work in Firefox?
(If this comment was disrespectful, please report it.)

 
2/6/2008 8:31:50 PMEnbient

Lewis, Thanks so much for sharing your knowledge and code with this community.

I must confess I am a complete newbie and have no idea how this code works. I am trying to insert this file upload data into a database along with several other text fields that I need to insert into the database which are text inputs. For example, for description, I added the text field below by using the following new lines in Upload.asp:

Dim Description
Description = Upload("Description").Value
Recordset.Fields("Description).Value = objUpload.Fields("File1).Description

Then I added a Public Description line to clsField.asp.

The record inserts without error, but when I check the description field in the database, it is empty.

Can anyone please tell me what I might be doing wrong? A million thanks.


(If this comment was disrespectful, please report it.)

 
3/18/2008 11:39:38 AMHelen

Nice work, Lewis.
Do you know how to add java script function that using excel web page display at classic asp? I have huge data coming from database and I want to add jscript function says "Please wait...." but it doesn't work. any idea?

Thanks
Helen
(If this comment was disrespectful, please report it.)

 
3/24/2008 1:16:09 PMSean Cunningham

In case anyone is dealing with this error:

Microsoft VBScript runtime (0x800A0046)
Permission denied
/cgi-bin/comments/clsField.asp, line 227

At least in my case, it's caused by a lack of IUSR_SERVERNAME permissions on the drive that I'm trying to access. So, to get around this and still use FSO, just comment out lines 224-234. The program will not be able to calculate and check for available free space, but presumably your host will have enough space anyway.
(If this comment was disrespectful, please report it.)

 
7/28/2008 9:54:48 AMMark Iliff, Talespinner

Fantastic stuff, Lewis. Way, way more professional than most free code... and some that you pay for too!

µ
(If this comment was disrespectful, please report it.)

 
8/22/2009 6:10:52 AMlems

Hi.. lewis the new version is pretty cool.. Thanks. I enjoy using it.
(If this comment was disrespectful, please report it.)

 
5/17/2010 9:15:39 AMPaula

I rarely (ok Never before now) would create an online account to leave a comment - but I have to say, for those of us occasionally supporting 8 year old code - thank-you so much for writing this code - it really solved a conundrum for me! THANK-YOU!
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.