Results 1 to 11 of 11

Thread: Pass & in a POST for fileupload

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Pass & in a POST for fileupload

    I am using a fileuploader i found online, however if i pass a filename with an & in it, on my POST form, it will not work.

    Any ideas on how to get this to passthrough?

    So for example, if i had a file named "Joe & Mitch File.doc"

    It will pass joesupload.asp?filename=Joe & Mitch File.doc

    It thinks that after the & there is a new variable..

    Thanks guys

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Pass & in a POST for fileupload

    it needs to be url encoded...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Pass & in a POST for fileupload

    Or do you know a good asp classic file uploader? that allows for & in the file name to be uploaded.

    Quote Originally Posted by techgnome View Post
    it needs to be url encoded...

    -tg
    how do i do that on my form?

    HTML Code:
    <HTML>
    <HEAD><TITLE></TITLE></HEAD>
    <BODY>
    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="uploadexmple.asp">
    <font size="1" face="Verdana"><b>Select a file to upload:</b></font><br><INPUT TYPE=FILE SIZE="15" NAME="FILE1"> <INPUT TYPE=SUBMIT VALUE="Upload">
    </FORM>
    </BODY>
    </HTML>
    Last edited by joefox; Sep 10th, 2009 at 09:08 PM.

  4. #4

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Pass & in a POST for fileupload

    Quote Originally Posted by joefox View Post
    Or do you know a good asp classic file uploader? that allows for & in the file name to be uploaded.



    how do i do that on my form?

    HTML Code:
    <HTML>
    <HEAD><TITLE></TITLE></HEAD>
    <BODY>
    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="uploadexmple.asp">
    <font size="1" face="Verdana"><b>Select a file to upload:</b></font><br><INPUT TYPE=FILE SIZE="15" NAME="FILE1"> <INPUT TYPE=SUBMIT VALUE="Upload">
    </FORM>
    </BODY>
    </HTML>
    I dont know if URLEncold will work, since when i get the form value of file1, it will think the & in the value is the string delimiter...right?

  5. #5

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Pass & in a POST for fileupload

    here is my complete code

    i dont know if its my form, or my upload script i found online, i think its the upload script since anything with a & in it dosent work

    uploadform.htm
    HTML Code:
    <HTML>
    <HEAD><TITLE></TITLE></HEAD>
    <BODY>
    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="uploadexmple.asp">
    <font size="1" face="Verdana"><b>Select a file to upload:</b></font><br><INPUT TYPE=FILE SIZE="15" NAME="FILE1"> <INPUT TYPE=SUBMIT VALUE="Upload">
    </FORM>
    </BODY>
    </HTML>
    uploadexample.asp
    HTML Code:
    <%
    Class FileUploader
    	Public  Files
    	Private mcolFormElem
    
    	Private Sub Class_Initialize()
    		Set Files = Server.CreateObject("Scripting.Dictionary")
    		Set mcolFormElem = Server.CreateObject("Scripting.Dictionary")
    	End Sub
    	
    	Private Sub Class_Terminate()
    		If IsObject(Files) Then
    			Files.RemoveAll()
    			Set Files = Nothing
    		End If
    		If IsObject(mcolFormElem) Then
    			mcolFormElem.RemoveAll()
    			Set mcolFormElem = Nothing
    		End If
    	End Sub
    
    	Public Property Get Form(sIndex)
    		Form = ""
    		If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
    	End Property
    
    	Public Default Sub Upload()
    		Dim biData, sInputName
    		Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
    		Dim nPosFile, nPosBound
    
    		biData = Request.BinaryRead(Request.TotalBytes)
    		nPosBegin = 1
    		nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
    		
    		If (nPosEnd-nPosBegin) <= 0 Then Exit Sub
    		 
    		vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
    		nDataBoundPos = InstrB(1, biData, vDataBounds)
    		
    		Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))
    			
    			nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
    			nPos = InstrB(nPos, biData, CByteString("name="))
    			nPosBegin = nPos + 6
    			nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
    			sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
    			nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
    			nPosBound = InstrB(nPosEnd, biData, vDataBounds)
    			
    			If nPosFile <> 0 And  nPosFile < nPosBound Then
    				Dim oUploadFile, sFileName
    				Set oUploadFile = New UploadedFile
    				
    				nPosBegin = nPosFile + 10
    				nPosEnd =  InstrB(nPosBegin, biData, CByteString(Chr(34)))
    				sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
    				oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))
    
    				nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
    				nPosBegin = nPos + 14
    				nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))
    				
    				oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
    				
    				nPosBegin = nPosEnd+4
    				nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
    				oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
    				
    				If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
    			Else
    				nPos = InstrB(nPos, biData, CByteString(Chr(13)))
    				nPosBegin = nPos + 4
    				nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
    				If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
    			End If
    
    			nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
    		Loop
    	End Sub
    
    	'String to byte string conversion
    	Private Function CByteString(sString)
    		Dim nIndex
    		For nIndex = 1 to Len(sString)
    		   CByteString = CByteString & ChrB(AscB(Mid(sString,nIndex,1)))
    		Next
    	End Function
    
    	'Byte string to string conversion
    	Private Function CWideString(bsString)
    		Dim nIndex
    		CWideString =""
    		For nIndex = 1 to LenB(bsString)
    		   CWideString = CWideString & Chr(AscB(MidB(bsString,nIndex,1))) 
    		Next
    	End Function
    End Class
    
    Class UploadedFile
    	Public ContentType
    	Public FileName
    	Public FileData
    	
    	Public Property Get FileSize()
    		FileSize = LenB(FileData)
    	End Property
    
    	Public Sub SaveToDisk(sPath)
    		Dim oFS, oFile
    		Dim nIndex
    	
    		If sPath = "" Or FileName = "" Then Exit Sub
    		If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
    	
    		Set oFS = Server.CreateObject("Scripting.FileSystemObject")
    		If Not oFS.FolderExists(sPath) Then Exit Sub
    		
    		Set oFile = oFS.CreateTextFile(sPath & FileName, True)
    		
    		For nIndex = 1 to LenB(FileData)
    		    oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
    		Next
    
    		oFile.Close
    	End Sub
    	
    	Public Sub SaveToDatabase(ByRef oField)
    		If LenB(FileData) = 0 Then Exit Sub
    		
    		If IsObject(oField) Then
    			oField.AppendChunk FileData
    		End If
    	End Sub
    
    End Class
    
    %>
    <head>
    </head>
    <body>
    
    <%
    
    	Dim Uploader, File
    	Set Uploader = New FileUploader
    	
    	' This starts the upload process
    	Uploader.Upload()
    
    	If Uploader.Files.Count = 0 Then
    		Response.Write "<b><font size=""1"" face=""Verdana"" color=""red""><b>Error</b> - File(s) not uploaded.</font>"
    	Else
    		' Loop through the uploaded files
    		For Each File In Uploader.Files.Items
    
    			'Save Data To Folder Path
    			File.SaveToDisk "D:\testarea
    	
    			Response.write "<img src=""../../images/link.gif""> <a href=""uploadform.htm""><font size=""1"" face=""Verdana"">Upload Another File</font></a>"
    
    		Next
    	End If
    
    %>
    
    </body>

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Pass & in a POST for fileupload

    If you are using POST, it shouldn't matter... the only time it does matter is if you are using GET, and are manipulating the data in the URL directly... using a form and POSTing or GETing it, it should be able to handle that for your automatically. Since you are using POST for the file, I'm not sure why you think it isn't working.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Pass & in a POST for fileupload

    Quote Originally Posted by techgnome View Post
    If you are using POST, it shouldn't matter... the only time it does matter is if you are using GET, and are manipulating the data in the URL directly... using a form and POSTing or GETing it, it should be able to handle that for your automatically. Since you are using POST for the file, I'm not sure why you think it isn't working.

    -tg
    Yes, if i use a file with & in it, for some reason it says my Uploader.Files.Count = 0 but there really is a file there...

    techgnome, anyway you can test on your end? I would be willing to pay a few bucks...

  8. #8
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Pass & in a POST for fileupload

    After correcting two errors in your sample code (post #5 of this thread), this upload script worked without error for me for files with "&" in the name. Presumably just typos, the errors were:

    Code:
    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="uploadexmple.asp">
    Should be "uploadexample.asp" - missing an "a."

    Code:
    File.SaveToDisk "D:\testarea
    Need to enclose the path string with a " at the end of the line.

  9. #9

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Pass & in a POST for fileupload

    I wonder why it works for you, and not for me?

    Quote Originally Posted by SambaNeko View Post
    After correcting two errors in your sample code (post #5 of this thread), this upload script worked without error for me for files with "&" in the name. Presumably just typos, the errors were:

    Code:
    <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="uploadexmple.asp">
    Should be "uploadexample.asp" - missing an "a."

    Code:
    File.SaveToDisk "D:\testarea
    Need to enclose the path string with a " at the end of the line.

  10. #10
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Pass & in a POST for fileupload

    Perhaps there's something about your file aside from just its name - have you tried other files with & in the name? Other file types? The one I tried was a .jpg. Large files can also cause issues on upload forms sometimes - how big is the file you're trying?

  11. #11

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Pass & in a POST for fileupload

    Quote Originally Posted by SambaNeko View Post
    Perhaps there's something about your file aside from just its name - have you tried other files with & in the name? Other file types? The one I tried was a .jpg. Large files can also cause issues on upload forms sometimes - how big is the file you're trying?
    Yes its just a text file, that is 20k its named Joe & Mitch.txt

    I dont think that is the problem, the problem seems to be when it checks if any files are avialble for upload, when i check the count it says 0 when i upload anything with a 0 in it.

Posting Permissions

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



Click Here to Expand Forum to Full Width