无组件上传类
来源:互联网 发布:网络电视盒子哪个最好 编辑:程序博客网 时间:2024/06/04 18:57
更快,更安全,更方便风声作品UpLoadClass对象[对象参考]
使用UpLoadClass对象可以处理一个HTTP表单上传二进制数据(文件)到服务器,其形式模拟ASP内置对象Request。上传的处理要创建一个UpLoadClass对象实例,可以使用<%Set request2=new UpLoadClass%>
参数属性 MaxSize每个上传文件的最大字节数
FileType允许上传的文件类型
默认值:153600
特征值:0表示文件大小不受限制
默认值:"gif/jpg"
特征值:""表示文件类型不受限制(空)SavePath文件存放的路径,可以是相对路径
默认值:"" 即当前目录AutoSave设置Open方法处理文件的方式,对其他方法无效
方法 Sub Open()打开对象,打开之前可以重定义对象参数属性MaxSize等
默认值:0
可选值:
0:取无重复的服务器时间字符串为文件名自动保存文件
1:取源文件名自动保存文件
2:不自动保存文件,Open之后请用Save/GetData方法保存文件
每个实例均需调用的方法。Function
Save(Item,Name)保存文件,成功保存返回ture,否则返回false
Item是表单中file元素
Name是保存的文件名,可选值:
0:自动取无重复的服务器时间字符串为文件名
1:自动取源文件名
字符串:自定义的文件名,如"mypic.jpg"Function Form(Item)对于其他表单元素:(假设表单元素名为item)
Function GetData(Item)获取数据流,可用来保存文件到数据库,试图获取非文件数据时返回空值返回属性(只读) Version返回类版本说明Error返回当前文件保存状态
Form(item) 表单元素对应的Value值
对于file表单元素:(假设表单元素名为item)
Form(item) 文件上传后的文件名
Form(item&"_Type") 文件类型,例"image/gif"
Form(item&"_Name") 原文件名
Form(item&"_Path") 原文件本地上传路径
Form(item&"_Size") 文件字节数
Form(item&"_Ext") 文件扩展名
Form(item&"_Err") 该文件上传状态
-1:没有文件上传
0:正常
1:文件超过大小
2:文件类型不正确
3:文件超过大小,类型不正确
对于images类file表单元素还有:(假设表单元素名为item)
Form(item&"_Width") 图片宽度
Form(item&"_Height")图片高度
-1:对象尚未打开,请先Open打开对象
0:正常
1:有文件超过大小
2:有文件类型不正确
3:有文件超过大小,类型不正确
4:异常退出FormItem保存Post表单中文本域名称的数组,下标从1开始FileItem保存Post表单中文件域名称的数组,下标从1开始UpLoadClass对象[专家说明]
1、建议直接修改类的63,64,65,66行为自己需要的默认设置,这样每次就不要设置同样的参数了
类的初始默认值分别为
p_MaxSize = 153600 单文件最大150K
p_FileType = "jpg/gif" 允许上传jpg/gif格式文件
p_SavePath = "" 在当前目录保存文件,这里是相对路径,如:“UpLoadFile/”
p_AutoSave = 0 自动生成无重复文件名保存目标文件
修改 p_SavePath = "UpLoadFile" 后类与Version1.02就基本兼容了2、文本域不同时刻的状态比较
项目对象打开前对象打开后.Form(Item)temp文本域内容3、文件域不同时刻的状态比较
项目对象
打开前对象打开后文件保存后无文件有文件无文件有文件且符合有文件不符合.Form(Item)temptemptemptemp目标文件名temp.Form(Item&"_TYPE")temptemp文件类型temp文件类型文件类型.Form(Item&"_Name")temptemp源文件名temp源文件名源文件名.Form(Item&"_Path")temptemp上传路径temp上传路径上传路径.Form(Item&"_Size")temptemp文件大小temp文件大小文件大小.Form(Item&"_Ext")temptemp扩展名temp扩展名扩展名.Form(Item&"_Err")temp-1temp-101/2/3注:
1)temp表示空字符串
2).Form(Item)=temp的时候,文件均不会保存到服务器上
3)自动保存模式(.AutoSave=0 or 1)文件保存与对象打开同时发生
4)手动保存模式(.AutoSave=2)文件保存发生在调用.Save(Item,FileName)时4、同名文件域上传,仅处理第一个,其他忽略。
UpLoadClass.asp
---------------------------------------------------------------------------------------------------------------------------------
<%
'----------------------------------------------------------
'***************** 风声无组件上传类 2.0 *****************
'作者:风声
'网站:http://www.17560.net http://www.54nb.com
'邮件:Rumor@17560.net
'版权:版权全体,源代码公开,各种用途均可免费使用
'**********************************************************
'----------------------------------------------------------Class UpLoadClass
Private p_MaxSize,p_FileType,p_SavePath,p_AutoSave,p_Error
Private objForm,binForm,binItem,strDate,lngTime
Public FormItem,FileItemPublic Property Get Version
Version="Rumor UpLoadClass Version 2.0"
End PropertyPublic Property Get Error
Error=p_Error
End PropertyPublic Property Get MaxSize
MaxSize=p_MaxSize
End Property
Public Property Let MaxSize(lngSize)
if isNumeric(lngSize) then
p_MaxSize=clng(lngSize)
end if
End PropertyPublic Property Get FileType
FileType=p_FileType
End Property
Public Property Let FileType(strType)
p_FileType=strType
End PropertyPublic Property Get SavePath
SavePath=p_SavePath
End Property
Public Property Let SavePath(strPath)
p_SavePath=replace(strPath,chr(0),"")
End PropertyPublic 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 PropertyPrivate 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 SubPrivate Sub Class_Terminate
objForm.RemoveAll
Set objForm = nothing
Set binItem = nothing
binForm.Close()
Set binForm = nothing
End SubPublic 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 binRequestDataDim 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,lngFsizintTemp=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 ifbinItem.Close()
p_start = p_end+intSeparator+2
loop Until p_start+3>lngRequestSize
FormItem=split(strFormItem,strSplit)
FileItem=split(strFileItem,strSplit)
End SubPrivate Function GetTimeStr()
lngTime=lngTime+1
GetTimeStr=strDate&lngTime
End FunctionPrivate 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 FunctionPublic 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 FunctionPublic 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 FunctionPublic Function Form(Item)
if objForm.Exists(Item) then
Form=objForm(Item)
else
Form=""
end if
End FunctionPrivate 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 FunctionPrivate 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 FunctionEnd Class
%>
- 无组件上传类
- 风声无组件上传类
- 风声无组件上传类
- 风声无组件上传类
- asp无组件上传类
- asp无组件上传类
- TUpload无组件上传类
- 无组件上传类.比如无惧上传类
- 化境ASP无组件上传类
- javascript无组件上传图片类
- 艾恩ASP无组件上传类 最新更新!!!!!
- 无组件上传
- 无组件上传控件
- 无组件上传
- 无组件上传
- 无组件上传
- 无组件上传图片
- ASP 无组件上传
- Remember One thing-Work is work,money is money
- 初认System.Transactions
- rome-rss
- 个人空间1.3版上线 -- 感谢! -- 使用报告 -- BUG与功能征集
- 网页制作中经常用到的六则代码技巧
- 无组件上传类
- "HTTP 错误 401.1 - 未经授权:访问由于凭据无效被拒绝"的另类解决方案
- 我的收藏
- PowerShell的双引号
- sed命令使用详解
- xmms乱码解决方法
- Oracle与Access在开发中的一些不同之处
- 非常实用的iis权限设置
- Eclipse+MyEclipse+Tomcat的配置