xman51
09-14-2005, 03:14 PM
Anyone have a good upload script that I can use, I can't seem to find any that work on the net. :confused: :eek: :confused:
Thanks in advance,
Xman51
Thanks in advance,
Xman51
|
Click to See Complete Forum and Search --> : I Need a good Upload Script!! xman51 09-14-2005, 03:14 PM Anyone have a good upload script that I can use, I can't seem to find any that work on the net. :confused: :eek: :confused: Thanks in advance, Xman51 Bullschmidt 09-14-2005, 04:48 PM And here is a pure ASP (i.e. no components) resource for letting the user upload a file which is something that was unfortunately not built into ASP: ASP File Upload Using VBScript by John R. Lewis - 7/10/2000 http://aspzone.com/articles/160.aspx The above free code has worked well for me and you can copy and paste the code sample which is white on gray (what were they thinking?) or just highlight it and it becomes black on white. xman51 09-15-2005, 10:39 AM BullSchmidt, I have copied and pasted the code you provided (THANK YOU!!!) but I am having an error with it on line 164 of the parseRequest() Sub :eek: strBRequest = Request.BinaryRead(lngTotalBytes) I Get the following error output: Request object error 'ASP 0206 : 80004005' Cannot call BinaryRead /Bisk-iNet/YourCustomSpace/UploadScript.asp, line 164 Cannot call BinaryRead after using Request.Form collection. File(s) Uploaded: 0 Other Form Element(s): 0 I don't understand enough about these functions to know what is wrong. I was attempting to upload a jpeg file. Does it matter what file type you upload??? :confused: Thanks in advance, Xman51 javazoom 09-17-2005, 09:38 AM You could try an applet : http://www.javazoom.net/applets/jclientupload/jclientupload.html This applet could upload files and fodlers to a web server. Your server-side script that handles upload request could be ASP, PHP, JSP ... Hope it helps. slyfox 09-17-2005, 01:10 PM you cannot use Request.binaryread and Request.form together on the same page... don't ask me why but it just won't work. xman51 09-22-2005, 11:06 AM OK, I have come this far, but now I don't understand what I have to do next... I have the following code on my html upload page: <!-- #include file="UploadScript.asp" --> <form method="post" enctype="multipart/form-data" action="Photos.asp" id="form1" name="form1"> Your Name:<br /><input type="text" name="YourName" /><br /><br /> Your File:<br /><input type="file" name="YourFile" /><br /><br /> <input type="submit" name="submit" value="Upload" /> </form> <hr /> <% Dim objUpload, lngLoop Dim SavePath ExtPath = nameID & "\Images\" SavePath = Server.MapPath(ExtPath) If Request.TotalBytes > 0 Then Set objUpload = New clsUpload %> File(s) Uploaded: <%= objUpload.Files.Count %> <br /><br /> <% For lngLoop = 0 to objUpload.Files.Count - 1 'If accessing this page annonymously, 'the internet guest account must have 'write permission to the path below. objUpload.Files.Item(lngLoop).Save SavePath %> Form Element Name: <%= objUpload.Files.Key(lngLoop) %> <br /> File Name: <%= objUpload.Files.Item(lngLoop).FileName %> <br /><br /> <% Next %> Other Form Element(s): <%= objUpload.Form.Count %> <br /><br /> <% For lngLoop = 0 to objUpload.Form.Count - 1 %> Form Element Name: <%= objUpload.Form.Key(lngLoop) %> <br /> Form Element Value: <%= objUpload.Form.Item(lngLoop) %> <br /><br /> <% Next End If %> and I double and triple checked to make sure I have all the code for the include file (I Do)... And when I use the form...it writes this to the page: -----------------------------7d512111021a Content-Disposition: form-data; name="YourName" Caption Test -----------------------------7d512111021a Content-Disposition: form-data; name="YourFile"; filename="C:\Documents and Settings\james-menendez\My Documents\My Pictures\alleysexy.jpg" Content-Type: image/pjpeg ےطےàJFIFHHےغC $.' ",#(7),01444'9=82<.342ےغC 2!!22222222222222222222222222222222222222222222222222ےہً@"ےؤےؤ;!1A"Qa2qپ‘،#B±ء3Rر$CSلr¢âًٌےؤےؤ%!1AQaq"2ءےع ?ً:6؛<¦<گG*>U ... a bunch of crazy characters fills the page I think it is the text version of the jpeg file I am attempting to upload...the file still doesn't upload to the server. Please will someone tell me what I am doing wrong???? :confused: :confused: Thanks in Advance, Bullschmidt 09-22-2005, 12:13 PM Be sure you don't use Request.Form(...) anywhere in Photos.asp (i.e. the page that gets posted to). Instead of something like this: YourName = Request.Form("YourName") You'd want to use something like this: YourName = objFileUpload.Form.Item("YourName") xman51 09-22-2005, 04:58 PM Bull.... None...zip...zilch... I made extra special sure this time. Thanks for your reply is there anything else you can think of? Thanks again, xman51 09-22-2005, 05:07 PM btw...here is my upload script for the include file. Did I miss anything??? :confused: <% Class clsCollection '=========================================================' ' This class is a pseudo-collection. It is not a real ' ' collection, because there is no way that I am aware ' ' of to implement an enumerator to support the ' ' For..Each syntax using VBScript classes. ' '=========================================================' Private m_objDicItems Private Sub Class_Initialize() Set m_objDicItems = Server.CreateObject("Scripting.Dictionary") m_objDicItems.CompareMode = vbTextCompare End Sub Public Property Get Count() Count = m_objDicItems.Count End Property Public Default Function Item(Index) Dim arrItems If IsNumeric(Index) Then arrItems = m_objDicItems.Items If IsObject(arrItems(Index)) Then Set Item = arrItems(Index) Else Item = arrItems(Index) End If Else If m_objDicItems.Exists(Index) Then If IsObject(m_objDicItems.Item(Index)) Then Set Item = m_objDicItems.Item(Index) Else Item = m_objDicItems.Item(Index) End If End If End If End Function Public Function Key(Index) Dim arrKeys If IsNumeric(Index) Then arrKeys = m_objDicItems Key = arrKeys(Index) End If End Function Public Sub Add(Name, Value) If m_objDicItems.Exists(Name) Then m_objDicItems.Item(Name) = Value Else m_objDicItems.Add Name, Value End If End Sub End Class Class clsFile '=========================================================' ' This class is used as a container for a file sent via ' ' an http multipart/form-data post. ' '=========================================================' Private m_strName Private m_strContentType Private m_strFileName Private m_Blob Public Property Get Name() Name = m_strName End Property Public Property Let Name(vIn) m_strName = vIn End Property Public Property Get ContentType() ContentType = m_strContentType End Property Public Property Let ContentType(vIn) m_strContentType = vIn End Property Public Property Get FileName() FileName = m_strFileName End Property Public Property Let FileName(vIn) m_strFileName = vIn End Property Public Property Get Blob() Blob = m_Blob End Property Public Property Let Blob(vIn) m_Blob = vIn End Property Public Sub Save(Path) Dim objFSO, objFSOFile Dim lngLoop Set objFSO = _ Server.CreateObject("Scripting.FileSystemObject") Set objFSOFile = objFSO.CreateTextFile( _ objFSO.BuildPath(Path, m_strFileName)) For lngLoop = 1 to LenB(m_Blob) objFSOFile.Write Chr(AscB(MidB(m_Blob, lngLoop, 1))) Next objFSOFile.Close End Sub End Class 'Code Listing #3 Private Function BStr2UStr(BStr) 'Byte string to Unicode string conversion Dim lngLoop BStr2UStr = "" For lngLoop = 1 to LenB(BStr) BStr2UStr = BStr2UStr & Chr(AscB(MidB(BStr,lngLoop,1))) Next End Function Private Function UStr2Bstr(UStr) 'Unicode string to Byte string conversion Dim lngLoop Dim strChar UStr2Bstr = "" For lngLoop = 1 to Len(UStr) strChar = Mid(UStr, lngLoop, 1) UStr2Bstr = UStr2Bstr & ChrB(AscB(strChar)) Next End Function Private Function URLDecode(Expression) 'Why doesn't ASP provide this functionality for us? Dim strSource, strTemp, strResult Dim lngPos strSource = Replace(Expression, "+", " ") For lngPos = 1 To Len(strSource) strTemp = Mid(strSource, lngPos, 1) If strTemp = "%" Then If lngPos + 2 < Len(strSource) Then strResult = strResult & _ Chr(CInt("&H" & Mid(strSource, lngPos + 1, 2))) lngPos = lngPos + 2 End If Else strResult = strResult & strTemp End If Next URLDecode = strResult End Function Private Sub ParseRequest() Dim lngTotalBytes, lngPosBeg, lngPosEnd Dim lngPosBoundary, lngPosTmp, lngPosFileName Dim strBRequest, strBBoundary, strBContent Dim strName, strFileName, strContentType Dim strValue, strTemp Dim objFile 'Grab the entire contents of the Request as a Byte string If Request.TotalBytes > 0 Then Response.BinaryWrite(Request.BinaryRead(Request.TotalBytes)) End If 'Find the first Boundary lngPosBeg = 1 lngPosEnd = _ InStrB(lngPosBeg, strBRequest, UStr2Bstr(Chr(13))) If lngPosEnd > 0 Then strBBoundary = _ MidB(strBRequest, lngPosBeg, lngPosEnd - lngPosBeg) lngPosBoundary = InStrB(1, strBRequest, strBBoundary) End If If strBBoundary = "" Then 'The form must have been submitted *without* 'ENCTYPE="multipart/form-data" 'But since we already called Request.BinaryRead, 'we can no longer access the Request.Form collection, 'so we need to parse the request and populate 'our own form collection. lngPosBeg = 1 lngPosEnd = _ InStrB(lngPosBeg, strBRequest, UStr2BStr("&")) Do While lngPosBeg < LenB(strBRequest) 'Parse the element and add it to the collection strTemp = BStr2UStr(MidB(strBRequest, _ lngPosBeg, lngPosEnd - lngPosBeg)) lngPosTmp = InStr(1, strTemp, "=") strName = URLDecode(Left(strTemp, lngPosTmp - 1)) strValue = URLDecode(Right(strTemp, _ Len(strTemp) - lngPosTmp)) m_objForm.Add strName, strValue 'Find the next element lngPosBeg = lngPosEnd + 1 lngPosEnd = InStrB(lngPosBeg, _ strBRequest, UStr2BStr("&")) If lngPosEnd = 0 Then lngPosEnd = LenB(strBRequest) + 1 End If Loop Else 'Form was submitted with ENCTYPE="multipart/form-data" 'Loop through all the boundaries, and parse them 'into either the Form or Files collections. Do Until (lngPosBoundary = _ InStrB(strBRequest, strBBoundary & UStr2Bstr("--"))) 'Get the element name lngPosTmp = InStrB(lngPosBoundary, strBRequest, _ UStr2BStr("Content-Disposition")) lngPosTmp = InStrB(lngPosTmp, _ strBRequest, UStr2BStr("name=")) lngPosBeg = lngPosTmp + 6 lngPosEnd = InStrB(lngPosBeg, _ strBRequest, UStr2BStr(Chr(34))) strName = BStr2UStr(MidB(strBRequest, _ lngPosBeg, lngPosEnd - lngPosBeg)) 'Look for an element named 'filename' lngPosFileName = InStrB(lngPosBoundary, _ strBRequest, UStr2BStr("filename=")) 'If found, we have a file, 'otherwise it is a normal form element If lngPosFileName <> 0 And lngPosFileName < _ InStrB(lngPosEnd, strBRequest, strBBoundary) Then 'It is a file. Get the FileName lngPosBeg = lngPosFileName + 10 lngPosEnd = InStrB(lngPosBeg, _ strBRequest, UStr2BStr(chr(34))) strFileName = BStr2UStr(MidB(strBRequest, _ lngPosBeg, lngPosEnd - lngPosBeg)) 'Get the ContentType lngPosTmp = InStrB(lngPosEnd, _ strBRequest, UStr2BStr("Content-Type:")) lngPosBeg = lngPosTmp + 14 lngPosEnd = InstrB(lngPosBeg, _ strBRequest, UStr2BStr(chr(13))) strContentType = BStr2UStr(MidB(strBRequest, _ lngPosBeg, lngPosEnd - lngPosBeg)) 'Get the Content lngPosBeg = lngPosEnd + 4 lngPosEnd = InStrB(lngPosBeg, _ strBRequest, strBBoundary) - 2 strBContent = MidB(strBRequest, _ lngPosBeg, lngPosEnd - lngPosBeg) If strFileName <> "" And strBContent <> "" Then 'Create the File object, 'and add it to the Files collection Set objFile = New clsFile objFile.Name = strName objFile.FileName = Right(strFileName, _ Len(strFileName) - InStrRev(strFileName, "\")) objFile.ContentType = strContentType objFile.Blob = strBContent m_objFiles.Add strName, objFile End If Else 'It is a form element 'Get the value of the form element lngPosTmp = InStrB(lngPosTmp, _ strBRequest, UStr2BStr(chr(13))) lngPosBeg = lngPosTmp + 4 lngPosEnd = InStrB(lngPosBeg, _ strBRequest, strBBoundary) - 2 strValue = _ BStr2UStr(MidB(strBRequest, _ lngPosBeg, lngPosEnd - lngPosBeg)) 'Add the element to the collection m_objForm.Add strName, strValue End If 'Move to Next Element lngPosBoundary = InStrB(lngPosBoundary + _ LenB(strBBoundary), strBRequest, strBBoundary) Loop End If End Sub Class clsUpload '=========================================================' ' This class will parse the binary contents of the ' ' request, and populate the Form and Files collections. ' '=========================================================' Private m_objFiles Private m_objForm Public Property Get Form() Set Form = m_objForm End Property Public Property Get Files() Set Files = m_objFiles End Property Private Sub Class_Initialize() Set m_objFiles = New clsCollection Set m_objForm = New clsCollection ParseRequest End Sub End Class %> Bullschmidt 09-22-2005, 05:46 PM I Get the following error output: Quote: Request object error 'ASP 0206 : 80004005' Cannot call BinaryRead /Bisk-iNet/YourCustomSpace/UploadScript.asp, line 164 Cannot call BinaryRead after using Request.Form collection. File(s) Uploaded: 0 Other Form Element(s): 0 It seems like from the code you posted that you think this error is initially triggered from the initial page with the form, but I think it is from the page that receives the post (i.e. Photos.asp). So what is the code on the page that receives the post and are you sure you're not using anything like Request.Form(...) on that page? xman51 09-22-2005, 05:49 PM I don't receive that error anymore. And the output is on the same page of the form. It posts all that garbage to the page that I posted a couple of replies ago. Still no request.form on the page I am using to upload or the page I have the form on (which is the same page) Thanks again, Bullschmidt 09-22-2005, 05:58 PM OK so now I'm trying to work through your code on Photos.asp and this may or may not be related but on line 12 you have this: ExtPath = nameID & "\Images\" But I don't see above that where the variable nameID is ever set. And shortly after that you have this: SavePath = Server.MapPath(ExtPath) But Server.MapPath() converts a virtual path (which may contain forward slashes such as mysite/images/) to a physical path (which may contain backward slashes such as c:\websites\myaccount\wwwroot\mysite\images\). But of course "\Images\" already contains backward slashes... vishalgupta 07-05-2006, 05:04 AM hey i've been trying following code... but giving me err.. plz help me out... <!--#INCLUDE FILE="clsUpload.asp"--> <% Dim objUpload Dim strFileName Dim strPath ' Instantiate Upload Class Set objUpload = New clsUpload ' Grab the file name strFileName = objUpload.Fields("file1").FileName ' Compile path to save file to strPath = Server.MapPath("/") & "\" & "file1_" & strFileName ' Save the binary data to the file system objUpload("file1").SaveAs strPath ' Release upload object from memory Set objUpload = Nothing Response.Redirect "demo.asp" %> <H2>To File System</H2> <FORM method="post" encType="multipart/form-data" action="file1.asp"> <INPUT type="File" name="file1"><INPUT type="Submit" name="up" value="Upload"> </FORM> <Hr> thanx n regards, vishal gupta webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |