调试一个博客发表的程序,不知为什么,总是提示错误信息如下:“Request对象,ASP0206(0x80004005)使用Request.Form集合之后,不能调用BinaryR
调试一个博客发表的程序,不知为什么,总是提示错误信息如下:
“Request 对象, ASP 0206 (0x80004005)使用 Request.Form 集合之后,不能调用 BinaryRead。”
我在网上查询后,得知使用request集合,就不能调用BinaryRead.,不知道是否这个原因。
请哪位大哥帮忙改一下下面的源代码。
<%
dim oUpFileStream
Class upload_file
dim Form,File,Version
Private Sub Class_Initialize
'定义变量
dim RequestBinDate,sStart,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
dim iFileSize,sFilePath,sFileType,sFormvalue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
'代码开始
Version="无组件上传类 Version 0.96"
set Form = Server.CreateObject("Scripting.Dictionary")
set File = Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes < 1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set oUpFileStream = Server.CreateObject("adodb.stream")
oUpFileStream.Type = 1
oUpFileStream.Mode = 3
oUpFileStream.Open
oUpFileStream.Write Request.BinaryRead(Request.TotalBytes)
oUpFileStream.Position=0
RequestBinDate = oUpFileStream.Read
iFormEnd = oUpFileStream.Size
bCrLf = chrB(13) & chrB(10)
'取得每个项目之间的分隔符
sStart = MidB(RequestBinDate,1, InStrB(1,RequestBinDate,bCrLf)-1)
iStart = LenB (sStart)
iFormStart = iStart+2
'分解项目
Do
iInfoEnd = InStrB(iFormStart,RequestBinDate,bCrLf & bCrLf)+3
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iFormStart
oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestBinDate,sStart)-1
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set oFileInfo= new FileInfo
'取得文件属性
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileName = GetFileName(sFileName)
oFileInfo.FilePath = GetFilePath(sFileName)
oFileInfo.FileExt = GetFileExt(sFileName)
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
oFileInfo.FileType = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileStart = iInfoEnd
oFileInfo.FileSize = iFormStart -iInfoEnd -2
oFileInfo.FormName = sFormName
file.add sFormName,oFileInfo
else
'如果是表单项目
tStream.Close
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
tStream.Position = 0
tStream.Type = 2
tStream.Charset = "gb2312"
sFormvalue = tStream.ReadText
form.Add sFormName,sFormvalue
end if
tStream.Close
iFormStart = iFormStart+iStart+2
'如果到文件尾了就退出
loop until (iFormStart+2) = iFormEnd
RequestBinDate=""
set tStream = nothing
End Sub
Private Sub Class_Terminate
'清除变量及对像
if not Request.TotalBytes<1 then
oUpFileStream.Close
set oUpFileStream =nothing
end if
Form.RemoveAll
File.RemoveAll
set Form=nothing
set File=nothing
End Sub
'取得文件路径
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function
'取得文件名
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function
'取得扩展名
Private function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1)
Else
GetFileExt = ""
End If
End function
End Class
'文件属性类
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
FileExt = ""
End Sub
'保存文件方法
Public function SaveToFile(FullPath)
dim oFileStream,ErrorChar,i
SaveToFile=1
if trim(fullpath)="" or right(fullpath,1)="/" then exit function
set oFileStream=CreateObject("Adodb.Stream")
oFileStream.Type=1
oFileStream.Mode=3
oFileStream.Open
oUpFileStream.position=FileStart
oUpFileStream.copyto oFileStream,FileSize
oFileStream.SaveToFile FullPath,2
oFileStream.Close
set oFileStream=nothing
SaveToFile=0
end function
End Class
%>
7 个解决方案
你发人家的类上来干什么,这个无组件上传类肯定是对的
把你使用这个类的页面的代码发上来
如果你把表单的enctype设置了"multipart/form-data"后,在使用request.form("xxx")后不肯定不能再使用BinaryRead了
使用上传类的页面的代码........
汗,怎么发了选择上传的页面?
post_diary.asp?submit=yes 这个页面
这是这个类之前的代码:
<%
If Request("submit") = "yes" Then
Call GetRandomize() '调用随机函数
ranFileName = GetRandomize
Set My_UpLoad=new upload_file
Title = ReplaceTitle(Trim(My_UpLoad.Form("Title")))
Content = Trim(My_UpLoad.Form("Body"))
AdminUserID = Trim(My_UpLoad.Form("AdminUserID"))
Sort_ID = Trim(My_UpLoad.Form("Sort_ID"))
srchfid = Trim(My_UpLoad.Form("srchfid"))
log_weather = Trim(My_UpLoad.Form("log_weather"))
Bbs_show = Trim(My_UpLoad.Form("Bbs_show"))
If Bbs_show = "" Then Bbs_show = 1 End If
If Not(IsNum(AdminUserID)) Then
Call bbs_ErrorMessage("会员ID传递数据丢失~~,请确定返回上一页。")
Response.End()
End If
filepath="upfile/"
Set File=My_UpLoad.File("files")
If File.fileSize>0 Then
'利用随机产生一列数字作为文件名
FileName=ranFileName+"."
filenameEnd=File.FileName
'确定扩展名
filenameEnd=Split(filenameEnd,".")
n=UBound(filenameEnd)
'文件名+扩展名
FileName=FileName&filenameEnd(n)
If LCase(filenameEnd(n))<>"gif" And LCase(filenameEnd(n))<>"jpg" Then
Response.Write("")
Response.End()
ElseIf File.fileSize > (200*1024) Then
Response.Write("")
Response.End()
End If
'设置保存路径
year1 = Year(Now())
month1 = Month(Now())
If Cint(month1)<10 Then month1="0"&month1
day1 = Day(Now())
If Cint(day1)<10 Then day1="0"&day1
hour1=Hour(Now())
If Cint(hour1)<10 Then hour1="0"&hour1
minute1=Minute(Now())
If Cint(minute1)<10 Then minute1="0"&minute1
If Cint(second1)<10 Then second1="0"&second1
Set fso = Server.CreateObject("Scripting.FileSystemObject")
strfolder=year1&"-"&month1&"-"&day1&""
If Not fso.folderexists(Server.MapPath("../bbs/"&filepath&strfolder)) Then
fso.CreateFolder(Server.MapPath("../bbs/"&filepath&strfolder))
End If
'filepath=strDir&"/"&filepath '文件保存路径
SavefullPath = "../bbs/"&filepath&strfolder&"/"&FileName
File.SaveToFile Server.MapPath(SavefullPath)
photopath = filepath&strfolder&"/"&FileName
Else
photopath = ""
End If
Set My_UpLoad=Nothing
Sql="Select * From D_blogdiary"
rs.Open Sql,Conn,1,3
rs.AddNew
rs("User_ID") = AdminUserID
rs("Sort_ID") = Sort_ID
rs("Title") = Title
rs("Content") = Content
rs("Createtime") = Now()
rs("Bbs_show") = Bbs_show
rs("Log_weather") = log_weather
rs("Photopath") = photopath
rs.Update
rs.Close
Conn.Execute("Update D_Member Set UserLife=UserLife+"&Post_Integral_calculus&",U_Integral=U_Integral+"&Post_Integral_calculus&" Where ID = "&AdminUserID&"")
'记录积分(谁操作,给谁加分,1=扣分0=加分,积分数,记录说明)
Call Add_Integral(AdminUserID,AdminUserID,0,Post_Integral_calculus,"博客发布新文章 - 主题["&Title&"]")
If Int(Bbs_show) = 2 Then
'写入论坛帖子
Sql="Select * From D_bbsforum"
rs.Open Sql,Conn,1,3
rs.Addnew
rs("User_ID") = AdminUserID
rs("Sorttwo") = srchfid
rs("Postip") = Request.ServerVariables("Remote_HOST")
rs("Topic") = ReplaceTitle(Title)
rs("Facial") = "0"
rs("Content") = Content
rs("Posttime") = Now()
rs("Pic_x") = photopath
'首先默认最后回复用户为发表人
rs("Lastuser") = petname
rs("Lasttime") = Now()
rs.Update
rs.Close
'更新访会员发表原帖数,加上经验值和体力值
Conn.Execute("Update D_Member Set UserLife=UserLife+"&Post_Integral_calculus&",U_Integral=U_Integral+"&Post_Integral_calculus&",Posttopic=Posttopic+1 Where ID = "&AdminUserID&"")
Call Add_Integral(AdminUserID,AdminUserID,0,Post_Integral_calculus,"社区发布新帖 - 主题["&Title&"]")
End If
Response.Write("")
Response.End()
End If
%>
If Request( "submit ") = "yes " Then =======>>这里使用了request了,所以无法使用binaryread
Call GetRandomize() '调用随机函数
ranFileName = GetRandomize
Set My_UpLoad=new upload_file ==========>这里的类使用了binaryread
应该怎么改呢?这里如果不用request那怎么办???谢谢啊!
删除
If Request( "submit ") = "yes " Then
和这个语句的结尾 end if
或者你需要验证submit时,可以将这个值加入session中,在binaryread前可以使用session但不能使用request.form这种代码