View Full Version : Having several problems with an ASP upload script. [RESOLVED - ADDED SOLUTION]

10-23-2007, 03:05 PM
I'm using Lewis Moten's uploading script and it works great except for several errors.

Class clsUpload 'Class name

The Code I'm using:

' Instantiate Upload Class
Set objUpload = New clsUpload

' Grab the file name
strFileName = objUpload.Fields("image").FileName

' Compile path to save file to
strPath = Server.MapPath(".") & "\" & pathName & "\" & strFileName

' Save the binary data to the file system
objUpload("image").SaveAs strPath
SQL = "INSERT INTO gallery ([path]"
For i = 0 To (objUpload.Count-2)
SQL = SQL & ",[" & objUpload(i).Name & "]"
SQL = Left(SQL,Len(SQL)-1)
SQL = SQL & ") VALUES ('" & strPath & "',"
For i = 0 To (objUpload.Count-2)
SQL = SQL & "'" & strFormat(objUpload.Fields(i).Value) & "'"
SQL = Left(SQL,Len(SQL)-1)
SQL = SQL & ")"
Response.Write SQL

End If
Set Conn = Nothing
'Set Rs = Nothing
Set objUpload = Nothing

The problems are:

Firefox: It doesn't get the FileName of the object nor the other form items.
FireFox/IE: Doesn't allow using indexes instead of names - ie: objUpload.Fields(0).Value Instead of objUpload.Fields("fieldName0").Value

It is essential for me to use indexes because my form items are varied and I don't know the names of them (Dynamic form).
Also, I'd like to get the other form's elements to be able to insert the rest of the information to the database.

Thanks in advance.

10-23-2007, 05:55 PM
I'm afraid I can't suggest changes to that ASP uploader, I don't know it and in any case I suspect that mucking about with binary form data is a bit beyond me. But I can suggest an alternative ASP upload script that works in pretty much an identical fashion and, at least when I've tried it, does do the things you need: Jacob Gilley's ASP upload script (http://www.asp101.com/articles/jacob/scriptupload.asp)?

10-23-2007, 09:04 PM
Ok I looked at the code of the class of the upload script and I found the problem there and fixed it. It works fine now.

Thanks for the suggestion SpudHead but I'm really comfortable with my current script.

I still have a problem with Firefox though.

10-24-2007, 01:52 AM
Ok. I solved the other one too. By looking at the code of the class again I managed to see that there are actually 2 ways of getting the name of the file element. The one is the FileName which works fine in IE and the other is FilePath.

That's all. Now it works perfectly fine.

Here's my fix that made indexing work in both Firefox and Internet Explorer [I marked the things I changed with the red color]:

Public Default Property Get Fields(ByVal pstrName)

Dim llngIndex ' Index of current field

' If a number was passed
If IsNumeric(pstrName) Then

llngIndex = CLng(pstrName)

' If programmer requested an invalid number
If llngIndex > mlngCount - 1 Or llngIndex < 0 Then
' Raise an error
Call Err.Raise(vbObjectError + 1, "clsUpload.asp", "Object does not exist within the ordinal reference.")
Exit Property
End If

' Return the field class for the index specified
Set Fields = mobjFieldAry(llngIndex)
Exit Property

' Else a field name was passed

' convert name to lowercase
pstrName = LCase(pstrname)

' Loop through each field
For llngIndex = 0 To mlngCount - 1

' If name matches current fields name in lowercase
If LCase(mobjFieldAry(llngIndex).Name) = pstrName Then

' Return Field Class
Set Fields = mobjFieldAry(llngIndex)
Exit Property

End If


End If

' If matches were not found, return an empty field
Set Fields = New clsField

' ' ERROR ON NonExistant:
' ' If matches were not found, raise an error of a non-existent field
' Call Err.Raise(vbObjectError + 1, "clsUpload.asp", "Object does not exist within the ordinal reference.")
' Exit Property

End Property

What did I do?

I saw that llngindex had the value of the index correctly but it was never used. So I inserted it to the mobjFieldAry instead of the value that was before: pstrName.

I also added Exit Property after it does find the proper value or else it will just continue looping untill it goes to the end of the function which sets the field value to nothing.

08-15-2009, 03:41 AM
Barr Man,

Thanks for this post, I recently had this error. What is strange is the script has been working perfect for 6 months, then stopped working suddenly with no clue why.

I have tried your patch and it doesn't fix the problem, so I am just going to use the FilePath property instead of the FileName property

My question is that you said it was working in IE and not Firefox. If this is a server-side script why should the browser work?

I am not sure what changed on my server, I was thinking some update to VBScript.

Thanks for any more info you can help me with, and am glad I found you post here.


Old Pedant
08-15-2009, 04:12 AM
It also depends on the *version* of MSIE.

FireFox (and other browsers) consider it a SECURITY ISSUE to send the entire path to the file on the user's computer and so *only* send the file name.

Actually, in the general case this makes sense. If you upload from a Linux box, for example, the path on your client box might be something like "//whatever/foo/file.xxx" whereas on a windows box it will be "D:\foo\file.xxx" or something like that.

The only thing that the two browser/clients have in common is just the "file.xxx" so that's all that the uploader *should* look for.

I think MSIE's passing along the client path is indeed a nasty error on MaxiSlop's part.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum