Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts

    Having several problems with an ASP upload script. [RESOLVED - ADDED SOLUTION]

    Hi.
    I'm using Lewis Moten's uploading script and it works great except for several errors.

    Code:
    Class clsUpload 'Class name
    The Code I'm using:
    Code:
    ' 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
    Response.Write(objUpload.Fields(1).Value)
    	SQL = "INSERT INTO gallery ([path]"
    	For i = 0 To (objUpload.Count-2)
    		SQL = SQL & ",[" & objUpload(i).Name & "]"
    	Next
    	SQL = Left(SQL,Len(SQL)-1)
    	SQL = SQL & ") VALUES ('" & strPath & "',"
    	For i = 0 To (objUpload.Count-2)
    		SQL = SQL & "'" & strFormat(objUpload.Fields(i).Value) & "'"
    	Next
    	SQL = Left(SQL,Len(SQL)-1)
    	SQL = SQL & ")"
    	Response.Write SQL
    	
    	'Conn.Execute(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.
    Last edited by BarrMan; 10-24-2007 at 12:59 AM.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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?

  • #3
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    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.

  • #4
    Senior Coder BarrMan's Avatar
    Join Date
    Feb 2005
    Location
    Israel.
    Posts
    1,644
    Thanks
    69
    Thanked 83 Times in 82 Posts
    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]:
    Code:
    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
    		Else
    		
    			' 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
    			
    			Next
    		
    		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?
    1. 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.
    2. 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.
    Last edited by BarrMan; 10-24-2007 at 12:59 AM.

  • #5
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Suddenly script goes wrong

    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.

    Gaoxing

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •