Request 对象 错误 'ASP 0206 : 80004005' 不能调用 BinaryRead
Request 对象 错误 'ASP 0206 : 80004005' 不能调用 BinaryRead
/vip/inc/upload_5xsoft.inc,行 24
使用 Request.Form 集合之后,不能调用 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
%>
下面是提交页面:
<!--#include file="../inc/Conn.asp"-->
<!--#include file="function.asp"-->
<!--#include file="inc/upload_5xsoft.inc"-->
<!--#include file="c_login.asp"-->
<%
'*******************************************
'自定义上传
'*******************************************
If Request("submit") = "upfileface" Then
Call GetRandomize() '调用随机函数
ranFileName = GetRandomize
Set UpLoad=new upload_file
sFace_Flag = Trim(UpLoad.Form("Face_Flag"))
sold_Userface = Trim(UpLoad.Form("old_Userface"))
filepath="upfile/"
Set File=UpLoad.File("upface")
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" And LCase(filenameEnd(n))<>"png" Then
Call bbs_ErrorMessage("不允许上传您选择的文件格式,请检查后重新上传~~!")
Response.End()
ElseIf File.fileSize > (150*1024) Then
Call bbs_ErrorMessage("您上传的文件太大,上传不成功,单个文件最大不能超过150kb~~!")
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
SavefullPath = "../bbs/"&filepath&strfolder&"/"&FileName
File.SaveToFile Server.MapPath(SavefullPath)
'If Int(sFace_Flag) = 1 Then
' Call DeleteFile("../bbs/"&sold_Userface)
'End If
'写入数据库
Sql="Select * From D_Member Where ID="&str_AdminUserID&""
rs.Open Sql,Conn,1,3
If Not(rs.Eof And rs.Eof) Then
rs("Userface") = filepath&strfolder&"/"&FileName
rs("Face_Flag") = 1 '更改为自定义
rs.Update
End If
rs.Close
Call bbs_SuccessMsg("您的自定义头像上传成功。",Request.ServerVariables("http_referer"))
Response.End()
Else
Call bbs_ErrorMessage("您忘记了选择一张图片作为您的形象图片了...")
Response.End()
End If
Set upload=Nothing
End If
Sql="Select * From D_Member Where ID="&str_AdminUserID&""
rs.Open Sql,Conn,1,1
If Not(rs.Eof And rs.Eof) Then
userFaceflag = rs("Face_Flag")
userUserface = rs("Userface")
End If
rs.Close
If userFaceflag = "1" Then
struserFace="<img src=images/activitysmall.gif alt=自定义头像 width=16 height=16 align=absmiddle>"
Else
struserFace_1="<img src=images/activitysmall.gif alt=系统默认头像 width=16 height=16 align=absmiddle>"
End If
%>
<html xmlns="http://www.
<head>
<script language="javascript">
function checkF()
{
if(document.myform.upface.value=="")
{
alert("请选择您要上传的图片!\n\n上传JPG、GIF格式图片,文件大小不超过150KB");
document.myform.upface.focus();
return false;
}
document.myform.Submit.disabled=true;
}
function showImg(path)
{
var HTML;
HTML="<img src='"+path+"' border=0 width=90 height=90>"
window.document.all.preview.innerHTML=HTML;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<link href="inc/Main_Css.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="29" align="center" class="Tab1">本地上传</td>
<td width="101" height="29" align="center" class="Tab2"><a href="systemface.asp" target="main" title="默认头像">默认头像</a></td>
<td height="29" align="center">?</td>
</tr>
<tr>
<td height="4" colspan="4" align="center" background="images/tabbar_level1_bk1.gif"></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top" class="ContentClass"><table width="100%" height="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top" style="padding-top:15px;">
<li>请选择一种方式设置您的头像,第一种为自定义上传您喜爱的图片作为头像<br>
<li>第二种系统提供的个性头像<br>
<br>
<table width="99%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CECECE">
<form action="bbs_face.asp?submit=upfileface" method="post" name="myform" enctype="multipart/form-data" onSubmit="return checkF()">
<tr>
<td height="28" bgcolor="#E5E5E5"><%=struserFace%><strong>上传我的自定义头像</strong>请点取下面的“浏览”按键选择您要上传的图片</td>
</tr>
<tr>
<td height="150" valign="middle" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="78%"><table width="400" border="0" cellpadding="5" cellspacing="0">
<tr>
<td>注意:上传JPG、GIF格式图片,文件大小不超过150KB。<br>
头像最佳比例宽200px高200px正方形图片。</td>
</tr>
<tr>
<td>选择头像
<input name="upface" type="file" class="textt" id="upface" onChange="showImg(this.value)" size="30"></td>
</tr>
<tr>
<td height="35" align="center"><input name="old_Userface" type="hidden" id="old_Userface" value="<%=userUserface%>">
<input name="Face_Flag" type="hidden" id="Face_Flag" value="<%=userFaceflag%>" size="10" maxlength="10">
<input name="Submit" type="submit" class="GoSubmit" value=" 提交上传 "></td>
</tr>
</table></td>
<td width="22%"><div id="preview" style="width:100px; height:100px; overflow:hidden"><a href="../bbs/user_info.asp?userinfo_id=<%=str_AdminUserID%>" target="_blank"><img src="../bbs/<%=userUserface%>" width="100" border="0"></a></div></td>
</tr>
</table>
</td>
</tr>
</form>
</table></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
请高人帮助解决,首先感谢,我的QQ:10763481
[[it] 本帖最后由 gph 于 2008-3-5 10:44 编辑 [/it]]