Request 对象 错误 'ASP 0206 : 80004005'

wuming88888 2007-12-05 10:57:45
Request 对象 错误 'ASP 0206 : 80004005'

不能调用 BinaryRead

/resource/webclass/edit/Upfile_class.asp,行 47

使用 Request.Form 集合之后,不能调用 BinaryRead。


Upfile_class.asp的内容:


<%
Dim oUpFileStream
Class UpFile_Class

Dim Form,File,Version,Err

Private Sub Class_Initialize
Version = "无惧上传类 Version V1.2"
Err = -1
End Sub

Private Sub Class_Terminate
If Err < 0 Then
Form.RemoveAll
Set Form = Nothing
File.RemoveAll
Set File = Nothing
oUpFileStream.Close
Set oUpFileStream = Nothing
End If
End Sub

Public Sub GetData (MaxSize)
Dim RequestBinData,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
Dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
Dim iFindStart,iFindEnd
Dim iFormStart,iFormEnd,sFormName
If Request.TotalBytes < 1 Then
Err = 1
Exit Sub
End If
If MaxSize > 0 Then
If Request.TotalBytes > MaxSize Then
Err = 2
Exit Sub
End If
End If
Set Form = Server.CreateObject ("Scripting.Dictionary")
Form.CompareMode = 1
Set File = Server.CreateObject ("Scripting.Dictionary")
File.CompareMode = 1
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
RequestBinData = oUpFileStream.Read
iFormEnd = oUpFileStream.Size
bCrLf = ChrB (13) & ChrB (10)
sSpace = MidB (RequestBinData,1, InStrB (1,RequestBinData,bCrLf)-1)
iStart = LenB (sSpace)
iFormStart = iStart+2
Do
iInfoEnd = InStrB (iFormStart,RequestBinData,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,RequestBinData,sSpace)-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_Class
iFindStart = InStr (iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr (iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileName = trim(Mid (sFileName,InStrRev (sFileName, "\")+1))
oFileInfo.FilePath = trim(Left (sFileName,InStrRev (sFileName, "\")))
oFileInfo.FileExt = trim(Mid (sFileName,InStrRev (sFileName, ".")+1))
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
If Form.Exists (sFormName) Then
Form (sFormName) = Form (sFormName) & ", " & sFormValue
else
form.Add sFormName,sFormValue
End If
End If
tStream.Close
iFormStart = iFormStart+iStart+2
Loop Until (iFormStart+2) > = iFormEnd
RequestBinData = ""
Set tStream = Nothing
End Sub
End Class

Class FileInfo_Class
Dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
Public Function SaveToFile (Path)
On Error Resume Next
Dim oFileStream
Set oFileStream = CreateObject ("ADODB.Stream")
oFileStream.Type = 1
oFileStream.Mode = 3
oFileStream.Open
oUpFileStream.Position = FileStart
oUpFileStream.CopyTo oFileStream,FileSize
oFileStream.SaveToFile Path,2
oFileStream.Close
Set oFileStream = Nothing
End Function

Public Function FileData
oUpFileStream.Position = FileStart
FileData = oUpFileStream.Read (FileSize)
End Function

End Class
%>
请问怎么解决呀,用的是2003
...全文
339 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuming88888 2007-12-06
  • 打赏
  • 举报
回复
大虾在吗
lkh42002 2007-12-05
  • 打赏
  • 举报
回复
你是哪个页面调用的?
wuming88888 2007-12-05
  • 打赏
  • 举报
回复
没明白您的意思,呵呵
lkh42002 2007-12-05
  • 打赏
  • 举报
回复
可能和select case Request("action") 这里有关系,
你把表单和上传分成两个文件处理
wuming88888 2007-12-05
  • 打赏
  • 举报
回复
Admin_upload.asp

如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!-- #include file="config.asp" -->

<!--#include FILE="edit/Upfile_class.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
<link href="site.css" rel="stylesheet" type="text/css">
</head>
<body style='MARGIN:0px;background:transparent;'>
<%

function change
dim ranNum
randomize
ranNum=int(90000*rnd)+10000
change=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
end function
select case Request("action")
case "upload"
call upload()
case else
call main()
end select
sub main()
%>
<SCRIPT language=javascript>
var checkimg=0;
function check()
{
var strFileName=form1.file.value;
var FileType;
var ImgWH;
if (strFileName=="")
{
alert("请选择要上传的文件");
return false;
}
else
{
FileType=strFileName.substr(strFileName.length-3)
FileType=FileType.toLowerCase();
if(FileType=="jpg" || FileType=="gif" )
{

if (checkimg==1)
{
//document.form1.file.value="";
alert("错误的图片文件!");
location.reload();
return false;
}

ImgWH=prompt("请输入图片的宽度和高度,中间用英文的逗号隔开:\n目前尺寸是图片的原始尺寸,如果不输入或者点“取消”按钮,将使用图片的实际大小。",""+document.form1.ImgWidth.value+","+document.form1.ImgHeight.value+"");
if (ImgWH!=null)
{
document.form1.ImgWidth.value=ImgWH.substr(0,ImgWH.indexOf(","));
document.form1.ImgHeight.value=ImgWH.substr(ImgWH.indexOf(",")+1);
}
}
else if(FileType=="swf")
{
ImgWH=prompt("请输入FLASH文件的宽度和高度,中间用英文的逗号隔开:","500,350");
if (ImgWH==null)
{
document.form1.ImgWidth.value=0
document.form1.ImgHeight.value=0
return false;
}
else
{
document.form1.ImgWidth.value=ImgWH.substr(0,ImgWH.indexOf(","));
document.form1.ImgHeight.value=ImgWH.substr(ImgWH.indexOf(",")+1);
}
}
}
}
</SCRIPT>
<table border="0" cellpadding="0" cellspacing="0">
<form name="form1" method="post" action="<%=Request.ServerVariables("SCRIPT_NAME")%>?action=upload" enctype="multipart/form-data" onSubmit="return check()">
<tr>
<td><input name="file" type="file" id="file" value="" size="20" onpropertychange="document.all.aaaa.src=this.value"> <input type="submit" name="Submit" value=" 提 交 "><input name="ImgWidth" type="hidden" id="ImgWidth"><input name="ImgHeight" type="hidden" id="ImgHeight"><input name="abc" type="hidden" id="abc" value="1"></td>
</tr>
</form>
</table>
<img name=aaaa onload="{checkimg=0;document.form1.ImgWidth.value=this.width;document.form1.ImgHeight.value=this.height;}" onerror="checkimg=1;">
<%
end sub
sub upload
dim file,upload,formpath,TempPath,upfile,uppictf,expname,picname,ImgWidth,ImgHeight,imgwidthinfo,info,strjs
dim formname,oFile,arrUpFileType,fileExt
uppictf=True
formpath=webuppath
if right(formpath,1)<>"/" then formpath=formpath&"/"
TempPath=year(now)& "-" &month(now)&"/"
call CreateDir(formpath&TempPath)
'set upload=new upload_5xsoft
set upload=new UpFile_Class
'set upfile=upload.file("file")

upload.GetData(104857600) '取得上传数据,限制最大上传100M
if upload.err > 0 then '如果出错
select case upload.err
case 1
uppictf=False
info="对不起,您没有选择文件!!!"
case 2
CloseDatabase
call alerts("你上传的文件总大小超出了最大限制(100M)")
exit sub
end select
end if

for each formName in upload.file '列出所有上传了的文件
set ofile=upload.file(formName) '生成一个文件对象
if ofile.filesize<100 then
info="请先选择你要上传的文件!"
uppictf=False
end if
if ofile.filesize>(webupsize*1024) then
CloseDatabase
call alerts("对不起,超出上传文件大小的限制("&webupsize&"K)!!!")
exit sub
end if

fileExt=lcase(ofile.FileExt)
arrUpFileType=split(webuptype,"|")
for i=0 to ubound(arrUpFileType)
if fileEXT=trim(arrUpFileType(i)) then
uppictf=true
exit for
end if
next
if fileEXT="asp" or fileEXT="asa" or fileEXT="aspx" or fileEXT="cer" or fileEXT="cdx" then
uppictf=false
end if
'------------------------------------------------------------------
if uppictf=True then
picname=change&"."&fileExt
else
info="对不起,错误的文件类型!!!"
end if
if uppictf=True then
'upfile.SaveAs Server.mappath(formPath&TempPath&picname)
ofile.SaveToFile Server.mappath(formPath&TempPath&picname) '保存文件
info="上传成功!!!"
end if
'set file=nothing
'next
ImgWidth=trim(upload.form("ImgWidth"))
ImgHeight=trim(upload.form("ImgHeight"))

if ImgWidth="" then
ImgWidth=0
else
ImgWidth=Clng(ImgWidth)
end if
if ImgHeight="" then
ImgHeight=0
else
ImgHeight=Clng(ImgHeight)
end if

response.write vbcrlf &"<script>" & vbcrlf
if uppictf=True then
strJS=strJS & "parent.message.focus();" & vbcrlf
strJS=strJS & "var range = parent.message.document.selection.createRange();" & vbcrlf
select case fileExt
case "jpg","gif"
strJS=strJS & "range.pasteHTML('<a href="& webuppath & TempPath & picname &" target=_blank><img src="& webuppath & TempPath & picname
if ImgWidth>0 then
strJS=strJS & " width=" & ImgWidth
end if
strJS=strJS & " onload=""if(this.width>520)this.width=500"""
if ImgHeight>0 then
strJS=strJS & " height=" & ImgHeight
end if
strJS=strJS & " border=0></a>');" & vbcrlf
strJS=strJS & "parent.form.Articleimage.checked=true;" & vbcrlf
strJS=strJS & "parent.form.Articleimgpath.value='"& webuppath & TempPath & picname&"';" & vbcrlf
strJS=strJS & "parent.form.DefaultPicList.options[parent.form.DefaultPicList.length] = new Option('" & webuppath & TempPath & picname & "','" & webuppath & TempPath & picname & "');" & vbcrlf
strJS=strJS & "parent.form.DefaultPicList.selectedIndex+=0;" & vbcrlf
case "swf"
strJS=strJS & "range.pasteHTML('<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=swflash/swflash.cab#version=6,0,29,0"
if ImgWidth>0 then
strJS=strJS & " width=" & ImgWidth
end if
if ImgHeight>0 then
strJS=strJS & " height=" & ImgHeight
end if
strJS=strJS & "><param name=movie value="& webuppath & TempPath & picname & ">"
strJS=strJS & "<param name=quality value=high>"
strJS=strJS & "<embed src="& webuppath & TempPath & picname & " quality=high pluginspage=http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash"
if ImgWidth>0 then
strJS=strJS & " width=" & ImgWidth
end if
if ImgHeight>0 then
strJS=strJS & " height=" & ImgHeight
end if
strJS=strJS & "></embed></object>');" & vbcrlf
case else
strJS=strJS & "range.pasteHTML('<a href="& webuppath & TempPath & picname & " target=_blank><img src=icon/" & fileExt & ".gif border=0 align=absmiddle> 附件</a>');" & vbcrlf
end select
strJS=strJS & "if(parent.form.Articlefiles.value==''){" & vbcrlf
strJS=strJS & "parent.form.Articlefiles.value+='" & webuppath & TempPath & picname & "';}" & vbcrlf
strJS=strJS & "else{" & vbcrlf & "parent.form.Articlefiles.value+='|'+'" & TempPath & picname & "';}" & vbcrlf
strJS=strJS & "alert('"&info&"');" & vbcrlf
strJS=strJS & "parent.message.focus();" & vbcrlf
response.write strJS
set file=nothing
else
response.write ("alert('"&info&"');") & vbcrlf
end if
next
response.write "history.go(-1);" & vbcrlf
response.write "</script>" & vbcrlf
end sub
CloseDatabase
%>
</body>
</html>

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧