Author |
Topic  |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 05 November 2001 : 01:43:41
|
Seems I cant have the two in one script....
Cannot use the generic Request collection after calling BinaryRead
I've tried everything I can think of, and everything Red Brad can think of, and everything Atomic can think of, and everything.... well you get the point, I went through alot of people before I came up with the conclusion that 1) this isnt solvable or 2)only one of the incredible programmers at snitz could solve this 
Below is the script... it *should* be self explanatory... where I'm having the problem is highlighted in red... I've tried request.form, just plain request, oUpload.form, oFile.form....
<!--#INCLUDE FILE="upload.class"--> <!--#include file="../_top.asp" --> <% Dim oUpload Dim oFile Dim sFileName Dim oFSO Dim sPath Dim sNewData Dim nLength Dim bytBinaryData
Const nForReading = 1 Const nForWriting = 2 Const nForAppending = 8
' grab the uploaded file data Set oUpload = New clsUpload Set oFile = oUpload("File1") ' parse the file name sFileName = oFile.FileName If Not InStr(sFileName, "\") = 0 Then sFileName = Mid(sFileName, InStrRev(sFileName, "\") + 1) End If
' Convert the binary data to Ascii bytBinaryData = oFile.BinaryData nLength = LenB(bytBinaryData) For nIndex = 1 To nLength sNewData = sNewData & Chr(AscB(MidB(bytBinaryData, nIndex, 1))) Next
' Save the file to the file system sPath = Server.MapPath(".\dl") & "\" Set oFSO = Server.CreateObject("Scripting.FileSystemObject") oFSO.OpenTextFile(sPath & sFileName, nForWriting, True).Write sNewData Set oFSO = Nothing Dim yname, yemail, ymod, yvers, yfile yname = request("yname") 'author name yemail = request("yemail")'author email ymod = request("ymod")'mod name yvers = request("yvers")'mod version yfile = sFileName Set oFile = Nothing Set oUpload = Nothing if not(IsNull(Trim(yname))) and not(IsNull(Trim(yemail))) and not(IsNull(Trim(ymod))) and not(IsNull(Trim(yvers))) then set uconn = Server.CreateObject("ADODB.Connection") strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/cgi-bin/toplist_dev.mdb") uconn.open strConnString strsql = "INSERT INTO UPLOADED (NAME, EMAIL, MODNAME, MODVERSION, MODFILE) Values(" & _ "'" & yname & "', '" & yemail & "', '" & ymod & "', '" & yvers & "', '" & yfile & "')" uconn.execute(strsql) response.write("<center>File Saved...<br></center>") response.write("<center><a href=""showmods.asp"">Mod Listing</a></center>") else response.write("<center>One or all fields were not filled in</center>") end if %> <!--#include file="../_bot.asp" -->
--------------- -Da_Stimulator |
|
HuwR
Forum Admin
    
United Kingdom
20595 Posts |
Posted - 05 November 2001 : 02:31:17
|
Fairly simple solution actually, what it is telling you is that you can't access any form fields after you have accessed the file, so in your code, move the code I have highlighted blue so that it is above the line in red.
[quote]
<!--#INCLUDE FILE="upload.class"--> <!--#include file="../_top.asp" --> <% Dim oUpload Dim oFile Dim sFileName Dim oFSO Dim sPath Dim sNewData Dim nLength Dim bytBinaryData
Const nForReading = 1 Const nForWriting = 2 Const nForAppending = 8
' grab the uploaded file data Set oUpload = New clsUpload Set oFile = oUpload("File1") ' parse the file name sFileName = oFile.FileName If Not InStr(sFileName, "\") = 0 Then sFileName = Mid(sFileName, InStrRev(sFileName, "\") + 1) End If
' Convert the binary data to Ascii bytBinaryData = oFile.BinaryData nLength = LenB(bytBinaryData) For nIndex = 1 To nLength sNewData = sNewData & Chr(AscB(MidB(bytBinaryData, nIndex, 1))) Next
' Save the file to the file system sPath = Server.MapPath(".\dl") & "\" Set oFSO = Server.CreateObject("Scripting.FileSystemObject") oFSO.OpenTextFile(sPath & sFileName, nForWriting, True).Write sNewData Set oFSO = Nothing Dim yname, yemail, ymod, yvers, yfile yname = request("yname") 'author name yemail = request("yemail")'author email ymod = request("ymod")'mod name yvers = request("yvers")'mod version yfile = sFileName Set oFile = Nothing Set oUpload = Nothing if not(IsNull(Trim(yname))) and not(IsNull(Trim(yemail))) and not(IsNull(Trim(ymod))) and not(IsNull(Trim(yvers))) then set uconn = Server.CreateObject("ADODB.Connection") strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("/cgi-bin/toplist_dev.mdb") uconn.open strConnString strsql = "INSERT INTO UPLOADED (NAME, EMAIL, MODNAME, MODVERSION, MODFILE) Values(" & _ "'" & yname & "', '" & yemail & "', '" & ymod & "', '" & yvers & "', '" & yfile & "')" uconn.execute(strsql) response.write("<center>File Saved...<br></center>") response.write("<center><a href=""showmods.asp"">Mod Listing</a></center>") else response.write("<center>One or all fields were not filled in</center>") end if %> <!--#include file="../_bot.asp" -->
This would depend on what your upload.class is doing with the other form variables. You may need to access them as part of the upload class rather than the request object
|
 |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 05 November 2001 : 02:48:03
|
Huw your a genious :) thx
--------------- -Da_Stimulator |
 |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 05 November 2001 : 02:51:38
|
Actually, now I'm getting the reverse, which is odd, because after my first test all went well, and my second test submission, I got the following error...
Cannot call BinaryRead after using Request collection.
--------------- -Da_Stimulator |
 |
|
Da_Stimulator
DEV Team Forum Moderator
    
USA
3373 Posts |
Posted - 05 November 2001 : 02:54:22
|
Ok more details... when I just use Request("whatever") to get the form fields, the data does not go through (the database is empty, except for the file name). When using request.form("whatever") I get the error above.
--------------- -Da_Stimulator |
 |
|
doddi
Starting Member
14 Posts |
Posted - 09 November 2001 : 13:42:22
|
try to use this upload method don't need to you use any components or anything ;)
<% Response.Clear byteCount = Request.TotalBytes RequestBin = Request.BinaryRead(byteCount) Dim UploadRequest Set UploadRequest = CreateObject("Scripting.Dictionary") BuildUploadRequest RequestBin
contentType = UploadRequest.Item("blob").Item("ContentType") filepathname = UploadRequest.Item("blob").Item("FileName") filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\")) value = UploadRequest.Item("blob").Item("Value")
yname = UploadRequest.Item("yname").Item("Value") yemail = UploadRequest.Item("yemail").Item("Value") ymod = UploadRequest.Item("ymod").Item("Value") yvers = UploadRequest.Item("yvers").Item("Value")
if (filepathname<>"") then
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject") pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-14 Set MyFile = ScriptObject.CreateTextFile(Left(Server.mappath(Request.ServerVariables("PATH_INFO")),pathEnd)&""&filename) For i = 1 to LenB(value) MyFile.Write chr(AscB(MidB(value,i,1))) Next MyFile.Close
end if
Dim connStr, rs connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("database.mdb")
Set rs = Server.CreateObject("ADODB.Recordset") rs.Open "TABLE", connStr, 1, 3 rs.AddNew
rs("yname") = yname rs("yemail") = yemail rs("ymod") = ymod rs("yvers") = yvers rs("yfile") = fileName rs.Update rs. Close Set rs = nothing
Sub BuildUploadRequest(RequestBin) 'Get the boundary PosBeg = 1 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13))) boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg) boundaryPos = InstrB(1,RequestBin,boundary) 'Get all data inside the boundaries Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--"))) 'Members variable of objects are put in a dictionary object Dim UploadControl Set UploadControl = CreateObject("Scripting.Dictionary") 'Get an object name Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition")) Pos = InstrB(Pos,RequestBin,getByteString("name=")) PosBeg = Pos+6 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34))) Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename=")) PosBound = InstrB(PosEnd,RequestBin,boundary) 'Test if object is of file type If PosFile<>0 AND (PosFile<PosBound) Then 'Get Filename, content-type and content of file PosBeg = PosFile + 10 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34))) FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) 'Add filename to dictionary object UploadControl.Add "FileName", FileName Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:")) PosBeg = Pos+14 PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13))) 'Add content-type to dictionary object ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) UploadControl.Add "ContentType",ContentType 'Get content of object PosBeg = PosEnd+4 PosEnd = InstrB(PosBeg,RequestBin,boundary)-2 Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg) Else 'Get content of object Pos = InstrB(Pos,RequestBin,getByteString(chr(13))) PosBeg = Pos+4 PosEnd = InstrB(PosBeg,RequestBin,boundary)-2 Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg)) End If 'Add content to dictionary object UploadControl.Add "Value" , Value 'Add dictionary object to main dictionary UploadRequest.Add name, UploadControl 'Loop to next object BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary) Loop
End Sub
'String to byte string conversion Function getByteString(StringStr) For i = 1 to Len(StringStr) char = Mid(StringStr,i,1) getByteString = getByteString & chrB(AscB(char)) Next End Function
'Byte string to string conversion Function getString(StringBin) getString ="" For intCount = 1 to LenB(StringBin) getString = getString & chr(AscB(MidB(StringBin,intCount,1))) Next End Function %>
|
 |
|
|
Topic  |
|
|
|