高人指点下这上传类该如何使用,谢谢。

叫我梁大侠 2010-07-23 12:16:45
上传类代码如下:
<%
Class UpLoadClass

Private p_MaxSize,p_FileType,p_SavePath,p_AutoSave,p_Error
Private objForm,binForm,binItem,strDate,lngTime
Public FormItem,FileItem

Public Property Get Version
Version="Rumor UpLoadClass Version 2.0"
End Property

Public Property Get Error
Error=p_Error
End Property

Public Property Get MaxSize
MaxSize=p_MaxSize
End Property
Public Property Let MaxSize(lngSize)
if isNumeric(lngSize) then
p_MaxSize=cdbl(lngSize)
end if
End Property

Public Property Get FileType
FileType=p_FileType
End Property
Public Property Let FileType(strType)
p_FileType=strType
End Property

Public Property Get SavePath
SavePath=p_SavePath
End Property
Public Property Let SavePath(strPath)
p_SavePath=replace(strPath,chr(0),"")
End Property

Public Property Get AutoSave
AutoSave=p_AutoSave
End Property
Public Property Let AutoSave(byVal Flag)
select case Flag
case 0:
case 1:
case 2:
case false:Flag=2
case else:Flag=0
end select
p_AutoSave=Flag
End Property

Private Sub Class_Initialize
p_Error = -1
p_MaxSize = 153600
p_FileType = "jpg/gif"
p_SavePath = ""
p_AutoSave = 0
strDate = replace(cstr(Date()),"-","")
lngTime = clng(timer()*1000)
Set binForm = Server.CreateObject("ADODB.Stream")
Set binItem = Server.CreateObject("ADODB.Stream")
Set objForm = Server.CreateObject("Scripting.Dictionary")
objForm.CompareMode = 1
End Sub

Private Sub Class_Terminate
objForm.RemoveAll
Set objForm = nothing
Set binItem = nothing
binForm.Close()
Set binForm = nothing
End Sub

Public Sub Open()
if p_Error=-1 then
p_Error=0
else
Exit Sub
end if
Dim lngRequestSize,binRequestData,strFormItem,strFileItem
Const strSplit="'"">"
lngRequestSize=Request.TotalBytes
if lngRequestSize<1 then
p_Error=4
Exit Sub
end if
binRequestData=Request.BinaryRead(lngRequestSize)
binForm.Type = 1
binForm.Open
binForm.Write binRequestData

Dim bCrLf,strSeparator,intSeparator
bCrLf=ChrB(13)&ChrB(10)

intSeparator=InstrB(1,binRequestData,bCrLf)-1
strSeparator=LeftB(binRequestData,intSeparator)

Dim p_start,p_end,strItem,strInam,intTemp,strTemp
Dim strFtyp,strFnam,strFext,lngFsiz
p_start=intSeparator+2
Do
p_end =InStrB(p_start,binRequestData,bCrLf&bCrLf)+3
binItem.Type=1
binItem.Open
binForm.Position=p_start
binForm.CopyTo binItem,p_end-p_start
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strItem=binItem.ReadText
binItem.Close()

p_start=p_end
p_end =InStrB(p_start,binRequestData,strSeparator)-1
binItem.Type=1
binItem.Open
binForm.Position=p_start
lngFsiz=p_end-p_start-2
binForm.CopyTo binItem,lngFsiz

intTemp=Instr(39,strItem,"""")
strInam=Mid(strItem,39,intTemp-39)

if Instr(intTemp,strItem,"filename=""")<>0 then
if not objForm.Exists(strInam&"_From") then
strFileItem=strFileItem&strSplit&strInam
if binItem.Size<>0 then
intTemp=intTemp+13
strFtyp=Mid(strItem,Instr(intTemp,strItem,"Content-Type: ")+14)
strTemp=Mid(strItem,intTemp,Instr(intTemp,strItem,"""")-intTemp)
intTemp=InstrRev(strTemp,"\")
strFnam=Mid(strTemp,intTemp+1)
objForm.Add strInam&"_Type",strFtyp
objForm.Add strInam&"_Name",strFnam
objForm.Add strInam&"_Path",Left(strTemp,intTemp)
objForm.Add strInam&"_Size",lngFsiz
if Instr(intTemp,strTemp,".")<>0 then
strFext=Mid(strTemp,InstrRev(strTemp,".")+1)
else
strFext=""
end if
if left(strFtyp,6)="image/" then
binItem.Position=0
binItem.Type=1
strTemp=binItem.read(10)
if strcomp(strTemp,chrb(255) & chrb(216) & chrb(255) & chrb(224) & chrb(0) & chrb(16) & chrb(74) & chrb(70) & chrb(73) & chrb(70),0)=0 then
if Lcase(strFext)<>"jpg" then strFext="jpg"
binItem.Position=3
do while not binItem.EOS
do
intTemp = ascb(binItem.Read(1))
loop while intTemp = 255 and not binItem.EOS
if intTemp < 192 or intTemp > 195 then
binItem.read(Bin2Val(binItem.Read(2))-2)
else
Exit do
end if
do
intTemp = ascb(binItem.Read(1))
loop while intTemp < 255 and not binItem.EOS
loop
binItem.Read(3)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,8),chrb(137) & chrb(80) & chrb(78) & chrb(71) & chrb(13) & chrb(10) & chrb(26) & chrb(10),0)=0 then
if Lcase(strFext)<>"png" then strFext="png"
binItem.Position=18
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
binItem.Read(2)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(57) & chrb(97),0)=0 or strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(55) & chrb(97),0)=0 then
if Lcase(strFext)<>"gif" then strFext="gif"
binItem.Position=6
objForm.Add strInam&"_Width",BinVal2(binItem.Read(2))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(2))
elseif strcomp(leftB(strTemp,2),chrb(66) & chrb(77),0)=0 then
if Lcase(strFext)<>"bmp" then strFext="bmp"
binItem.Position=18
objForm.Add strInam&"_Width",BinVal2(binItem.Read(4))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(4))
end if
end if
objForm.Add strInam&"_Ext",strFext
objForm.Add strInam&"_From",p_start
intTemp=GetFerr(lngFsiz,strFext)
if p_AutoSave<>2 then
objForm.Add strInam&"_Err",intTemp
if intTemp=0 then
if p_AutoSave=0 then
strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
end if
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
objForm.Add strInam,strFnam
end if
end if
else
objForm.Add strInam&"_Err",-1
end if
end if
else
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strTemp=binItem.ReadText
if objForm.Exists(strInam) then
objForm(strInam) = objForm(strInam)&","&strTemp
else
strFormItem=strFormItem&strSplit&strInam
objForm.Add strInam,strTemp
end if
end if

binItem.Close()
p_start = p_end+intSeparator+2
loop Until p_start+3>lngRequestSize
FormItem=split(strFormItem,strSplit)
FileItem=split(strFileItem,strSplit)
End Sub

Private Function GetTimeStr()
lngTime=lngTime+1
GetTimeStr=strDate&lngTime
End Function

Private Function GetFerr(lngFsiz,strFext)
dim intFerr
intFerr=0
if lngFsiz>p_MaxSize and p_MaxSize>0 then
if p_Error=0 or p_Error=2 then p_Error=p_Error+1
intFerr=intFerr+1
end if
if Instr(1,LCase("/"&p_FileType&"/"),LCase("/"&strFext&"/"))=0 and p_FileType<>"" then
if p_Error<2 then p_Error=p_Error+2
intFerr=intFerr+2
end if
GetFerr=intFerr
End Function

Public Function Save(Item,strFnam)
Save=false
if objForm.Exists(Item&"_From") then
dim intFerr,strFext
strFext=objForm(Item&"_Ext")
intFerr=GetFerr(objForm(Item&"_Size"),strFext)
if objForm.Exists(Item&"_Err") then
if intFerr=0 then
objForm(Item&"_Err")=0
end if
else
objForm.Add Item&"_Err",intFerr
end if
if intFerr<>0 then Exit Function
if VarType(strFnam)=2 then
select case strFnam
case 0:strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
case 1:strFnam=objForm(Item&"_Name")
end select
end if
binItem.Type = 1
binItem.Open
binForm.Position = objForm(Item&"_From")
binForm.CopyTo binItem,objForm(Item&"_Size")
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
binItem.Close()
if objForm.Exists(Item) then
objForm(Item)=strFnam
else
objForm.Add Item,strFnam
end if
Save=true
end if
End Function

Public Function GetData(Item)
GetData=""
if objForm.Exists(Item&"_From") then
if GetFerr(objForm(Item&"_Size"),objForm(Item&"_Ext"))<>0 then Exit Function
binForm.Position = objForm(Item&"_From")
GetData=binFormStream.Read(objForm(Item&"_Size"))
end if
End Function

Public Function Form(Item)
if objForm.Exists(Item) then
Form=objForm(Item)
else
Form=""
end if
End Function

Private Function BinVal2(bin)
dim lngValue,i
lngValue = 0
for i = lenb(bin) to 1 step -1
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
BinVal2=lngValue
End Function

Private Function Bin2Val(bin)
dim lngValue,i
lngValue = 0
for i = 1 to lenb(bin)
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
Bin2Val=lngValue
End Function

End Class
%>
上传页面代码:
<form name="reg" action="admin_checkimg.asp?reg=1" onSubmit="" enctype="multipart/form-data">
<table width="552" height="48" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<input type="file" name="CompVisualize" id="CompVisualize">
</td>
</tr>
<tr>
<td width="273">
<input type="submit" name="button" id="button" value="提交">
</td>
<td width="279"> </td>
</tr>
</table>
</form>
admin_checkimg.asp代码如下:
字数有限,见下面
...全文
117 26 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
把图片存在一个变量里,然后像平常一样的数据写库就可以了啊
叫我梁大侠 2010-07-24
  • 打赏
  • 举报
回复
额 这问题我已经弄好了的 还是谢谢你哦
我现在就是不知道怎么将那图片存入到数据库中
  • 打赏
  • 举报
回复
使用 Request.Form 集合之后,不能调用 BinaryRead。
/天缘装饰/UpLoadClass.asp, 第 114 行

在file中域不能使用Request.Form 接受数据
叫我梁大侠 2010-07-24
  • 打赏
  • 举报
回复
哎 自己帮自己顶下
难道就没哪位高人曾经或现在用的是风声上传图片类么??
叫我梁大侠 2010-07-24
  • 打赏
  • 举报
回复
感谢帮助我的人,问题基本上处理好了,由衷的感谢你们,谢谢!
叫我梁大侠 2010-07-24
  • 打赏
  • 举报
回复
大哥 你讲的有点深奥哦 能详细一点么
是不是把图片的那个path存进数据库?
我这研究了一个人家存数据库的
他存进数据库的就是那图片的路径
我按他的写的却发现数据库中没有存到
大哥指点下 谢谢。
叫我梁大侠 2010-07-23
  • 打赏
  • 举报
回复
<!--#include file = "inc/conn.asp" -->
<!--#include file = "inc/config.asp"-->
<!--#include file = "admin_upload.asp"-->
<%
select case request("reg")
case "1"
call uploadimg()
case "editimg"
call editimg()
case "deleimg"
call deleimg()
end select
%>
<%
sub uploadimg()
uploadpath=SaveUpFilesPath&"/"
uploadsize=MaxFileSize
uploadtype=UpFileType
Set Uprequest=new UpLoadClass
Uprequest.SavePath=uploadpath
Uprequest.MaxSize=uploadsize*1024
Uprequest.FileType=uploadtype
AutoSave=true
Uprequest.open
response.write "<script language=""javascript"">parent.reg.CompVisualize.value='"&Uprequest.SavePath&Uprequest.Form("file")&"';"
response.write "</script>"
response.write "<div style=""padding-top:5px;padding-bottom:5px;""> <font color=red>文件上传成功</font> [<a href='javascript:history.go(-1)'>重新上传</a>]</div>"
img = Request("CompVisualize")
if img <> "" then
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from admin_workimg "
rs.open sql,conn,3,3
rs.addnew
rs("title")= title
rs("time")=date()
rs("img")= img
rs.update
response.Write "<script>alert('成功添加图片!')</script>"
else
Response.Write("<script language=""JavaScript"">alert(""图片上传不成功!"");history.go(-1);</script>")
end if
Set Uprequest=nothing
end sub
%>
<%
sub editimg()

end sub
%>
<%
sub deleimg()

end sub
%>
调试没报错,只是什么都没显示,望高人指点下这admin_checkimg.asp页面代码哪里错,该怎么写,我研究了一晚上了,直到现在还是摸不着头脑,跪谢。
yousite1 2010-07-23
  • 打赏
  • 举报
回复
把On error resume next去掉就可以查出错误是什么了。
估计你页面上有使用了这句!
  • 打赏
  • 举报
回复
你要先测试上传图片的那部分,图片是否上传成功了,然后再写入库的部分
叫我梁大侠 2010-07-23
  • 打赏
  • 举报
回复
谢谢大哥
可是我把那段防黑客、SQL注入的代码删掉了,调试通过了,可是数据库还是没存到图片信息额
叫我梁大侠 2010-07-23
  • 打赏
  • 举报
回复
额 恩 有
怎么重写哦?谢谢
叫我梁大侠 2010-07-23
  • 打赏
  • 举报
回复

谢谢大哥
lzp4881 2010-07-23
  • 打赏
  • 举报
回复
太长了,慢慢调试,不要着急。
竹林听雨2005 2010-07-23
  • 打赏
  • 举报
回复
你是不是在conn.asp里写了一些防黑客、SQL注入的代码呢?这里提示的错误,就是在调用BinaryRead之前,肯定有代码在读request.form内容了。

我以前遇到过这样的情况,删除或重写那段代码就行了。
叫我梁大侠 2010-07-23
  • 打赏
  • 举报
回复
我现在用那个风声的上传图片类,可以上传到文件夹里面,可以却存不进数据库,高人指点下,我贴下我写的那段:
<!--#include file="UpLoadClass.asp"-->
<!--#include file="inc/conn.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>成品图片上传</title>
</head>
<%
set request0 = new UploadClass
request0.Charset="gb2312"
request0.FileType = "rar/zip/gif/jpg/swf"
request0.Savepath = "UploadFiles/"
request0.MaxSize = 1024*900
request0.open
%>
<body>
<div align="center">
<%
Response.Write "<div>产品图片:"&request0.Form("Photo_Path")&request0.Form("Photo_Name")
Response.Write "<div><a href='javascript:history.back();'>返回</a></div>"
dim strimg
strimg = request0.form("Photo")
set rs = server.CreateObject("adodb.recordset")
sql = "select * from admin_workimg"
rs.open sql,conn,3,3
rs.addnew
rs("img") = strimg
rs.update
rs.close
set rs=nothing
set request2=nothing
%>
</div>
</body>
</html>
调试结果说
错误类型:
Request 对象, ASP 0206 (0x80004005)
使用 Request.Form 集合之后,不能调用 BinaryRead。
/天缘装饰/UpLoadClass.asp, 第 114 行

那个类不可能错的,应该是我写入数据库那段代码出错了,高人指点下,谢谢。如果需要那类的代码我现在贴上,谢谢。
叫我梁大侠 2010-07-23
  • 打赏
  • 举报
回复
额 谢谢啊 可是我我昨晚从6点弄到快1点 都还是那样的结果额
qq43695548 2010-07-23
  • 打赏
  • 举报
回复
检查一下目录权限吧
SNOYC 2010-07-23
  • 打赏
  • 举报
回复
不是组件的问题,是你程序的问题。。conn里的错误
叫我梁大侠 2010-07-23
  • 打赏
  • 举报
回复
我的那个代码版本是V2.11的
叫我梁大侠 2010-07-23
  • 打赏
  • 举报
回复
我去下了个风声的上传图片类,可是还是不明白自己怎么去写那一段。哪位高人用过风声的,写个简单的列子我借鉴下,谢谢。
加载更多回复(6)

28,409

社区成员

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

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