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.
Terms of Agreement:
By using this article, you agree to the following terms...
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.
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.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
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
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.
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
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
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
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.
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.
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
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:
Create folder called Upload in your c:\Inetpub\wwwroot directory.
Copy clsUpload.asp to the folder
Copy clsField.asp to the folder
Set the permissions for your Internet Guest Account to have the rites to write,
read, and modify the upload folder.
Create an ASP page called Form.asp with the following code:
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
%>
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.
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.
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.
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
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 mustdisable 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 %>
<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.
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.
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
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
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
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
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
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
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
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
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
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")
Set RecordSet = Nothing
Set Connection = Nothing
Set Upload = Nothing
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
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">
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.
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.
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
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.
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
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
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
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
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.
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
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.
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.
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.
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
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
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
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"?
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
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.
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).
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)
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
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.
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:
Re-scan downloaded files using your personal virus checker before using it.
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...
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.
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.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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 span> (If this comment was disrespectful, please report it.)
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 span> (If this comment was disrespectful, please report it.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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...
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...
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)
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.)