2 k573071 k573071 于 2013.06.27 14:20 提问

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

网站程序以前都是对的,突然爆这个错误了。环境是2003 IIS6.0
uplaod.asp代码如下


图片上传
<%
'设置需要的参数
dim pw,ph,pinput,pdiv,mybg,fpath,tpath
pw = request("pw")
ph = request("ph")
pinput = request("pinput")
pdiv = request("pdiv")
mybg = request("mybg")
fpath = request("fpath")
tpath = request("tpath")
if tpath = "" then
tpath = fpath
end if
%>

<!-- body { background-color:#<%=mybg%>; margin:0; padding:0; } .fno{ margin:0; padding:0; } .updiv{ overflow:hidden; width:317px; height:30px; margin:0; padding:0; margin-top:2px; } .sub{ height:22px; font-size:12px; cursor:pointer; } --> <p>
 


do_upLoad.asp代码如下:





<%
'将当前的日期和时间转为文件名
dim pw,ph,pinput,pdiv,mybg,fpath,tpath
pw = request("pw")
ph = request("ph")
pinput = request("pinput")
pdiv = request("pdiv")
mybg = request("mybg")
fpath = request("fpath")
tpath = request("tpath")
'response.Write(pw&"|"&ph&"|"&pinput&"|"&pdiv&"|"&mybg&"|"&fpath&"|"&tpath)
'response.End()%>
<!-- body { background-color:#<%=mybg%>; margin-left: 0px; margin-top: 0px; font-size:12px; line-height:28px; } body a{ color:#FF0000; } --> <p>

<%
function makefilename()
dim fname
fname = now()
fname = trim(fname)
fname = replace(fname,"-","")
fname = replace(fname,"/","")
fname = replace(fname," ","")
fname = replace(fname,":","")
fname = replace(fname,"PM","")
fname = replace(fname,"AM","")
fname = replace(fname,"上午","")
fname = replace(fname,"下午","")
makefilename=fname
end function

dim upload,file,formName,formPath,mc
dim i,l,fileType,newfilename,filenamelist
'创建新文件名称
newfilename = makefilename()
'建立上传对象
set upload=new upload_5xsoft
'上传文件目录
set myfso = Server.CreateObject("Scripting.FileSystemObject")
if not myfso.folderexists(Server.MapPath(tpath)) then
myfso.createfolder(Server.MapPath(tpath))
end if

formPath = Server.mappath(tpath)&"/"
'列出所有上传了的文件
for each formName in upload.objFile
'生成一个文件对象
set file=upload.file(formName)
mc= upload.form("mc")
'如果 FileSize > 0 说明有文件数据
if file.FileSize>0 then
'取得文件扩展名

fileType = file.FileName '文件名以及扩展名
i = instr(fileType,".") '是否存在“.”
l = Len(fileType)

if i>0 then
fileType = Right(fileType,l-i+1) '得到扩展名
end if
newfilename = newfilename & fileType
filenamelist = formPath & newfilename '新文件绝对地址和名称
file.SaveAs filenamelist ''保存文件
end if
set file=nothing
If ChkImg(tpath&"/"&newfilename) Then
response.write "parent.document.getElementById(&#39;&quot;&amp;pinput&amp;&quot;&#39;).value=&#39;&quot;&amp;tpath&amp;&quot;/&quot;&amp;newfilename&amp;&quot;&#39;;parent.document.getElementById(&#39;&quot;&amp;pdiv&amp;&quot;&#39;).innerHTML=&#39;<img src="""&fpath&"/"&newfilename&""" height="""&ph&""" width="""&pw&""" />&#39;;"
response.Write("文件上传成功,你可以重新上传")
response.End()
Else
if myfso.fileexists(Server.MapPath(tpath&"/"&newfilename)) then
myfso.deletefile(Server.MapPath(tpath&"/"&newfilename))
end if
response.Write("此文件可能含有病毒,请重新上传")
response.End()
End If
next
set myfso=nothing
set upload=nothing ''删除此对象

Function ChkImg(img)
On Error Resume Next '为了捕获错误信息,需要让代码在出错时能继续执行
Dim RetunValue, ChkJpeg
RetunValue = True
'如果路径为空,则认为图片不合法
If isnull(img) Then ChkImg = False:Exit Function

Set ChkJpeg = Server.CreateObject("Persits.Jpeg") 
If -2147221005 <> Err Then    '如果组件被支持,则用组件检查图片的合法性
    ChkJpeg.Open Server.mappath(img)
    If Err Then
        RetunValue = False
    End If        
Else    '如果组件不被支持,则跳过直接返回True
    RetunValue = True
End If
'必要的善后工作
If Err.number <> 0 Then Err.clear
Set ChkJpeg = Nothing

ChkImg = RetunValue

End Function
%>

upload_5xsoft.inc 代码如下:

dim Data_5xsoft Class upload_5xsoft dim objForm,objFile,Version Public function Form(strForm) strForm=lcase(strForm) if not objForm.exists(strForm) then Form="" else Form=objForm(strForm) end if end function Public function File(strFile) strFile=lcase(strFile) if not objFile.exists(strFile) then set File=new FileInfo else set File=objFile(strFile) end if end function Private Sub Class_Initialize dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile dim iFileSize,sFilePath,sFileType,sFormValue,sFileName dim iFindStart,iFindEnd dim iFormStart,iFormEnd,sFormName Version="化境HTTP上传程序 Version 2.1" set objForm=Server.CreateObject("Scripting.Dictionary") set objFile=Server.CreateObject("Scripting.Dictionary") if Request.TotalBytes<1 then Exit Sub set tStream = Server.CreateObject("adodb.stream") set Data_5xsoft = Server.CreateObject("adodb.stream") Data_5xsoft.Type = 1 Data_5xsoft.Mode =3 Data_5xsoft.Open Data_5xsoft.Write Request.BinaryRead(Request.TotalBytes) Data_5xsoft.Position=0 RequestData =Data_5xsoft.Read iFormStart = 1 iFormEnd = LenB(RequestData) vbCrlf = chrB(13) & chrB(10) sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1) iStart = LenB (sStart) iFormStart=iFormStart+iStart+1 while (iFormStart + 10) < iFormEnd iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3 tStream.Type = 1 tStream.Mode =3 tStream.Open Data_5xsoft.Position = iFormStart Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart tStream.Position = 0 tStream.Type = 2 tStream.Charset ="gb2312" sInfo = tStream.ReadText tStream.Close '取得表单项目名称 iFormStart = InStrB(iInfoEnd,RequestData,sStart) iFindStart = InStr(22,sInfo,"name=""",1)+6 iFindEnd = InStr(iFindStart,sInfo,"""",1) sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart)) '如果是文件 if InStr (45,sInfo,"filename=""",1) > 0 then set theFile=new FileInfo '取得文件名 iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10 iFindEnd = InStr(iFindStart,sInfo,"""",1) sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart) theFile.FileName=getFileName(sFileName) theFile.FilePath=getFilePath(sFileName) theFile.FileExt=GetFileExt(sFileName) '取得文件类型 iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14 iFindEnd = InStr(iFindStart,sInfo,vbCr) theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart) theFile.FileStart =iInfoEnd theFile.FileSize = iFormStart -iInfoEnd -3 theFile.FormName=sFormName if not objFile.Exists(sFormName) then objFile.add sFormName,theFile end if else '如果是表单项目 tStream.Type =1 tStream.Mode =3 tStream.Open Data_5xsoft.Position = iInfoEnd Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3 tStream.Position = 0 tStream.Type = 2 tStream.Charset ="gb2312" sFormValue = tStream.ReadText tStream.Close if objForm.Exists(sFormName) then objForm(sFormName)=objForm(sFormName)&", "&sFormValue else objForm.Add sFormName,sFormValue end if end if iFormStart=iFormStart+iStart+1 wend RequestData="" set tStream =nothing End Sub Private Sub Class_Terminate if Request.TotalBytes>0 then objForm.RemoveAll objFile.RemoveAll set objForm=nothing set objFile=nothing Data_5xsoft.Close set Data_5xsoft =nothing end if End Sub Private function GetFilePath(FullPath) If FullPath <> "" Then GetFilePath = left(FullPath,InStrRev(FullPath, "\")) Else GetFilePath = "" End If End function Private function GetFileExt(FullPath) If FullPath <> "" Then GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1) Else GetFileExt = "" End If End function Private function GetFileName(FullPath) If FullPath <> "" Then GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1) Else GetFileName = "" End If End function End Class Class FileInfo dim FormName,FileName,FilePath,FileSize,FileExt,FileType,FileStart Private Sub Class_Initialize FileName = "" FilePath = "" FileSize = 0 FileStart= 0 FormName = "" FileType = "" FileExt = "" End Sub Public function SaveAs(FullPath) dim dr,ErrorChar,i SaveAs=true if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function set dr=CreateObject("Adodb.Stream") dr.Mode=3 dr.Type=1 dr.Open Data_5xsoft.position=FileStart Data_5xsoft.copyto dr,FileSize dr.SaveToFile FullPath,2 dr.Close set dr=nothing SaveAs=false end function End Class

检查了很久实在找不出原因来,求大神指点

1个回答

wangyaninglm
wangyaninglm   Ds   Rxr 2015.01.17 00:46
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!