Frågan 2 nov. 2000 14:25 #1 Nu är det fast kört, det vill inte fungera. Får felet:
Sub BuildUploadRequest(RequestBin)
Detta fel uppkommer på sida insert.asp:
'form.asp
<form enctype="multipart/form-data" method="post" action="insert.asp">
<font style=" font-size=11px " face="verdana">
Rubrik:<br>
<input type="text" name="rubrik"><br>
Skribent:<br>
<input type="text" name="skribent"><br>
Skribent:<br>
<input type="text" name="genre"><br>
<input type="text" name="val1"><br>
<input type="text" name="val2"><br>
<input type="text" name="val3"><br>
<input type="text" name="val4"><br>
Epost:<br>
<input type="text" name="epost"><br>
<% If request.querystring("typ")= "artikel" then response.write "Artikel:" else response.write "Spel:" end if%><br>
<input type="file" name="introb"><br>
<input type="file" name="file1"><br>
<input type="file" name="file2"><br>
<input type="file" name="file3"><br>
<input type="file" name="file4"><br>
<input type="file" name="file5"><br>
<input type="file" name="file6"><br>
<input type="file" name="file7"><br>
<input type="file" name="file8"><br>
Artikel:<br>
<textarea cols="30" rows="20" name="artikel"></textarea><br>
<input type="hidden" name="typ" value="<%=request.querystring("typ")%>">
<input type="submit">
</form>
' Fälten är bara utskrivna lite slarvigt, men de ska fungera.
'insert.asp
<%
response.buffer = true
Set Connection = Server.CreateObject("ADODB.Connection")
Connection.Open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("\cgi-bin/databas.mdb")
%>
<%
' Author Philippe Collignon
' Email PhCollignon@email.com
Response.Expires=0
Response.Buffer = TRUE
Response.Clear
'Response.BinaryWrite(Request.BinaryRead(Request.TotalBytes))
byteCount = Request.TotalBytes
'Response.BinaryWrite(Request.BinaryRead(varByteCount))
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
'email = UploadRequest.Item("email").Item("Value")
for each fobj in UploadRequest
if UploadRequest.Item(fobj).Item("FileName")<>"" then
contentType = UploadRequest.Item(fobj).Item("ContentType")
filepathname = UploadRequest.Item(fobj).Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item(fobj).Item("Value")
'Create FileSytemObject Component
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
'Create and Write to a File
pathEnd = Len(Server.mappath(Request.ServerVariables("PATH_INFO")))-14
' Set MyFile = ScriptObject.CreateTextFile(Left(Server.mappath(Request.ServerVariables("PATH_INFO")),pathEnd)&filename)
Set MyFile = ScriptObject.CreateTextFile(Server.mappath("\cgi-bin/"&filename))
'response.write(Server.mappath(filename))
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next
MyFile.Close
%>
<%
' Beginning of the second part
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
%>
<%
introb = request.form("introb")
introb = Right(introb,Len(introb)-InstrRev(introb,"\"))
file1s = request.form("file1")
file1s = Right(file1,Len(file1)-InstrRev(file1,"\"))
file2s = request.form("file2")
file2s = Right(file2,Len(file2)-InstrRev(file2,"\"))
file3s = request.form("file3")
file3s = Right(file3,Len(file3)-InstrRev(file3,"\"))
file4s = request.form("file4")
file4s = Right(file4,Len(file4)-InstrRev(file4,"\"))
file5 = request.form("file5")
file5 = Right(file5,Len(file5)-InstrRev(file5,"\"))
file6 = request.form("file6")
file6 = Right(file6,Len(file6)-InstrRev(file6,"\"))
file7 = request.form("file7")
file7 = Right(file7,Len(file7)-InstrRev(file7,"\"))
file8 = request.form("file8")
file8 = Right(file8,Len(file8)-InstrRev(file8,"\"))
laggtill = "INSERT INTO Artiklar "
laggtill = laggtill & "(Typ, Rubrik, Introbild, Artikel, Val1, Val2, Val3, Val4, Genre, SScreen1, SScreen2, SScreen3, SScreen4, Screen1, Screen2, Screen3, Screen4, Skribent, Epost) "
laggtill = laggtill & "VALUES('" & Trim(Request.Form("typ")) & "', '" & Trim(Request.Form("rubrik")) & "', '" & introb & "', '" & Trim(Request.Form("artikel")) & "', '" & Trim(Request.Form("val1")) & "', '" & Trim(Request.Form("val2")) & "', '" & Trim(Request.Form("val3")) & "', '" & Trim(Request.Form("val4")) & "', '" & Trim(Request.Form("genre")) & "', '" & file1s & "', '" & file2s & "', '" & file3s & "', '" & file4s & "', '" & file5 & "', '" & file6 & "', '" & file7 & "', '" & file8 & "', '" & Trim(Request.Form("skribent")) & "', '" & Trim(Request.Form("epost")) & "'); "
connection.execute(laggtill)
%>
Tacksam för en lösning på detta, kanske kluriga problem.
Andreas
[Redigerat av AG den 02 nov 2000]