20. marts 2005 - 01:34Der er
9 kommentarer og 1 løsning
Cannot use Request.Form
Hej Eksperter
Jeg får denne fejl: "Cannot use Request.Form collection after calling BinaryRead."
Jeg har prøvet at skrive upload.form i stedet, virker heller ikke ;o(
Koden er: ----------------------------------------------------------------------------------------------------------- <% Dim oUpload Dim oFile Dim sFileName Dim oFSO Dim sPath Dim sNewData Dim nLength Dim bytBinaryData Dim folder
' 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
function get_new_name() MaxNum = 0 Set fs = Server.CreateObject( "Scripting.FileSystemObject" ) folder = server.mappath("../userfiles/"&lcase(Unique_Name)&"/pictures") & "\" Set myFolder = fs.GetFolder(folder)
temp_file = 0 for each thing in myfolder.files temp_file = left(thing.name,len(thing.name)-4) 'response.write temp_file if int(temp_file) > int(maxnum) then MaxNum = temp_file end if next
get_new_name = int(MaxNum) + 1 end function
sFileName = get_new_name&".jpg"
Set oFSO = Server.CreateObject("Scripting.FileSystemObject") oFSO.OpenTextFile(folder & sFileName, nForWriting, True).Write sNewData Set oFSO = Nothing
Set oFile = Nothing Set oUpload = Nothing
Response.write("Billedet er uploaded!!!") %> <% Picture_Name = Request.form("Picture_Name") 'Opretter billede i databasen Set rs_add_picture = Server.CreateObject("ADODB.RecordSet") rs_add_picture.open "Select * From [Pictures]" , Conn,1,3 rs_add_picture.Addnew rs_add_picture("Site_Id") = Site_Id rs_add_picture("Picture_Name") = Picture_Name rs_add_picture("Picture_Url") = sFileName rs_add_picture.Update %> -----------------------------------------------------------------------------------------------------------
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
-------------------------------------------------------------------------------------- Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'form'
/admin/pictures.asp, line 91 -------------------------------------------------------------------------------------- <% Dim oUpload Dim oFile Dim sFileName Dim oFSO Dim sPath Dim sNewData Dim nLength Dim bytBinaryData Dim folder
' 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
function get_new_name() MaxNum = 0 Set fs = Server.CreateObject( "Scripting.FileSystemObject" ) folder = server.mappath("../userfiles/"&lcase(Unique_Name)&"/pictures") & "\" Set myFolder = fs.GetFolder(folder)
temp_file = 0 for each thing in myfolder.files temp_file = left(thing.name,len(thing.name)-4) 'response.write temp_file if int(temp_file) > int(maxnum) then MaxNum = temp_file end if next
get_new_name = int(MaxNum) + 1 end function
sFileName = get_new_name&".jpg"
Set oFSO = Server.CreateObject("Scripting.FileSystemObject") oFSO.OpenTextFile(folder & sFileName, nForWriting, True).Write sNewData Set oFSO = Nothing
Response.write("Billedet er uploaded!!!")
Picture_Name = oUpload.form("Picture_Name") 'Opretter billede i databasen Set rs_add_picture = Server.CreateObject("ADODB.RecordSet") rs_add_picture.open "Select * From [Pictures]" , Conn,1,3 rs_add_picture.Addnew rs_add_picture("Site_Id") = Site_Id rs_add_picture("Picture_Name") = Picture_Name rs_add_picture("Picture_Url") = sFileName rs_add_picture.Update
' 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
function get_new_name() MaxNum = 0 Set fs = Server.CreateObject( "Scripting.FileSystemObject" ) folder = server.mappath("../userfiles/"&lcase(Unique_Name)&"/pictures") & "\" Set myFolder = fs.GetFolder(folder)
temp_file = 0 for each thing in myfolder.files temp_file = left(thing.name,len(thing.name)-4) 'response.write temp_file if int(temp_file) > int(maxnum) then MaxNum = temp_file end if next
get_new_name = int(MaxNum) + 1 end function
sFileName = get_new_name&".jpg"
Set oFSO = Server.CreateObject("Scripting.FileSystemObject") oFSO.OpenTextFile(folder & sFileName, nForWriting, True).Write sNewData Set oFSO = Nothing
Response.write("Billedet er uploaded!!!")
Picture_Name = oUpload.Form.Item("Picture_Name") 'Opretter billede i databasen Set rs_add_picture = Server.CreateObject("ADODB.RecordSet") rs_add_picture.open "Select * From [Pictures]" , Conn,1,3 rs_add_picture.Addnew rs_add_picture("Site_Id") = Site_Id rs_add_picture("Picture_Name") = Picture_Name rs_add_picture("Picture_Url") = sFileName rs_add_picture.Update
Jeg inkluderer denne fil: <!--#include file="upload.class"-->
som indeholder: <% ' ------------------------------------------------------------------------------ ' Container of Field Properties Class clsField Public FileName Public ContentType Public Value Public FieldName Public Length Public BinaryData End Class ' ------------------------------------------------------------------------------ Class clsUpload ' ------------------------------------------------------------------------------ Private nFieldCount Private oFields()
' ------------------------------------------------------------------------------ Public Property Get Count() Count = nFieldCount End Property ' ------------------------------------------------------------------------------ Public Default Property Get Field(ByRef asFieldName) Dim lnLength Dim lnIndex
lnLength = UBound(oFields)
If IsNumeric(asFieldName) Then If lnLength >= asFieldName And asFieldName > -1 Then Set Field = oFields(asFieldName) Else Set Field = New clsField End If Else For lnIndex = 0 To lnLength If LCase(oFields(lnIndex).FieldName) = LCase(asFieldName) Then Set Field = oFields(lnIndex) Exit Property End If Next Set Field = New clsField End If End Property ' ------------------------------------------------------------------------------ Public Function Exists(ByRef avKeyIndex) Exists = Not IndexOf(avKeyIndex) = -1 End Function ' ------------------------------------------------------------------------------ Public Property Get ValueOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property ValueOf = oFields(lnIndex).Value End Property ' ------------------------------------------------------------------------------ Public Property Get FileNameOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property FileNameOf = oFields(lnIndex).FileName End Property ' ------------------------------------------------------------------------------ Public Property Get LengthOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property LengthOf = oFields(lnIndex).LengthOf End Property ' ------------------------------------------------------------------------------ Public Property Get BinaryDataOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property BinaryDataOf = oFields(lnIndex).BinaryData End Property ' ------------------------------------------------------------------------------ Private Function IndexOf(ByVal avKeyIndex) Dim lnIndex If IsNumeric(asFieldName) Then avKeyIndex = CLng(avKeyIndex) If nFieldCount > avKeyIndex And avKeyIndex > -1 Then IndexOf = avKeyIndex Else IndexOf = -1 End If Else For lnIndex = 0 To nFieldCount - 1 If LCase(oFields(lnIndex).FieldName) = LCase(avKeyIndex) Then IndexOf = lnIndex Exit Function End If Next IndexOf = -1 End If End Function ' ------------------------------------------------------------------------------ Public Property Get ContentTypeOf(ByRef avKeyIndex) Dim lnIndex lnIndex = IndexOf(avKeyIndex) if lnIndex = -1 Then Exit Property ContentTypeOf = oFields(lnIndex).ContentType End Property ' ------------------------------------------------------------------------------ Private Sub Class_Terminate() For lnIndex = 0 To nFieldCount - 1 Set oFields(0) = Nothing Next End Sub ' ------------------------------------------------------------------------------ Private Sub Class_Initialize()
Dim lnBytes ' Bytes received from the client Dim lnByteCount ' Number of bytes received Dim lnStartPosition ' Position at which content begins Dim lnEndPosition ' Position at which content ends
Dim loDic ' Contains properties of each ' specific field ' Local dictionary object(s) ' to be appended to class-scope ' dictioary object.
Dim lnBoundaryBytes ' Bytes contained within the current boundary Dim lnBoundaryStart ' Position at wich the current boundary begins ' within the lnBytes binary data. Dim lnBoundaryEnd ' Position at wich the current boundary ends ' within the lnBytes binary data. Dim lnDispositionPosition
Dim lsFieldName ' Name of the current field being parsed from ' Binary Data Dim lsFileName ' Name of the file within the current boundary Dim lnFileNamePosition ' Location of file name within current boundary
' Parse Content lnStartPosition = InstrB(lnDispositionPosition, lnBytes, CStrB(vbCr)) + 4 lnEndPosition = InstrB(lnStartPosition, lnBytes, lnBoundaryBytes) - 2 Value = CStrU(MidB(lnBytes,lnStartPosition,lnEndPosition-lnStartPosition)) loField.Value = Value loField.Length = Len(Value) End If
Set oFields(UBound(oFields)) = loField
'Loop to next object lnBoundaryStart = InstrB(lnBoundaryStart + LenB(lnBoundaryBytes), lnBytes, lnBoundaryBytes)
Set loField = Nothing
Loop
End Sub ' ------------------------------------------------------------------------------ Private Function CStrU(ByRef psByteString) Dim lnLength Dim lnPosition lnLength = LenB(psByteString) For lnPosition = 1 To lnLength CStrU = CStrU & Chr(AscB(MidB(psByteString, lnPosition, 1))) Next End Function ' ------------------------------------------------------------------------------ Private Function CStrB(ByRef psUnicodeString) Dim lnLength Dim lnPosition lnLength = Len(psUnicodeString) For lnPosition = 1 To lnLength CStrB = CStrB & ChrB(AscB(Mid(psUnicodeString, lnPosition, 1))) Next End Function ' ------------------------------------------------------------------------------ End Class ' ------------------------------------------------------------------------------ %>
Så ville det være super fedt - giver gerne ekstra point... Det er lidt noget haste noget :o)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.