asp多文件上传类.docx
- 文档编号:15724255
- 上传时间:2023-07-07
- 格式:DOCX
- 页数:17
- 大小:19.08KB
asp多文件上传类.docx
《asp多文件上传类.docx》由会员分享,可在线阅读,更多相关《asp多文件上传类.docx(17页珍藏版)》请在冰点文库上搜索。
asp多文件上传类
asp多文件上传类,是从我们服务器上搞来的是病毒
<%@LANGUAGE="VBSCRIPT"CODEPAGE="936"%>
<%
functionGetFilePath(FullPath,str)
IfFullPath<>""Then
GetFilePath=left(FullPath,InStrRev(FullPath,str))
Else
GetFilePath=""
EndIf
Endfunction
%>
<%
classclsUp'文件上传类
'------------------------
DimForm,File
DimAllowExt_'答应上传类型(白名单)
DimNoAllowExt_'不答应上传类型(黑名单)
PrivateoUpFileStream'上传的数据流
PrivateisErr_'错误的代码,0或true表示无错
PrivateErrMessage_'错误的字符串消息
PrivateisGetData_'指示能否已施行过GETDATA进程
'------------------------------------------------------------------
'类的属性
PublicPropertyGetVersion
Version="上传类声明"
EndProperty
PublicPropertyGetisErr'错误的代码,0或true表示无错
isErr=isErr_
EndProperty
PublicPropertyGetErrMessage'错误的字符串消息
ErrMessage=ErrMessage_
EndProperty
PublicPropertyGetAllowExt'答应上传类型(白名单)
AllowExt=AllowExt_
EndProperty
PublicPropertyLetAllowExt(Value)'答应上传类型(白名单)
AllowExt_=LCase(Value)
EndProperty
PublicPropertyGetNoAllowExt'不答应上传类型(黑名单)
NoAllowExt=NoAllowExt_
EndProperty
PublicPropertyLetNoAllowExt(Value)'不答应上传类型(黑名单)
NoAllowExt_=LCase(Value)
EndProperty
'----------------------------------------------------------------
'类实古代码
'初始化类
PrivateSubClass_Initialize
isErr_=0
NoAllowExt=""'黑名单,能够在这里预设不可上传的文件类型,以文件的后缀名来判别,不分大大写,每个每缀名用;号分开,假如黑名单为空,则判别白名单
NoAllowExt=LCase(NoAllowExt)
AllowExt=""'白名单,能够在这里预设可上传的文件类型,以文件的后缀名来判别,不分大大写,每个后缀名用;号分开
AllowExt=LCase(AllowExt)
isGetData_=false
EndSub
'类结束
PrivateSubClass_Terminate
onerrorResumeNext
'肃清变量及对像
Form.RemoveAll
SetForm=Nothing
File.RemoveAll
SetFile=Nothing
oUpFileStream.Close
SetoUpFileStream=Nothing
EndSub
'分析上传的数据网站制作
PublicSubGetData(MaxSize)
'定义变量
onerrorResumeNext
ifisGetData_=falsethen
DimRequestBinDate,sSpace,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
DimsFormValue,sFileName
DimiFindStart,iFindEnd
DimiFormStart,iFormEnd,sFormName
'代码开端
IfRequest.TotalBytes<1Then'假如没有数据上传
isErr_=1
ErrMessage_="没有数据上传"
ExitSub
EndIf
IfMaxSize>0Then'假如限制大小
IfRequest.TotalBytes>MaxSizeThen
isErr_=2'假如上传的数据超出限制大小
ErrMessage_="上传的数据超出限制大小"
ExitSub
EndIf
EndIf
SetForm=Server.CreateObject("Scripting.Dictionary")
Form.CompareMode=1
SetFile=Server.CreateObject("Scripting.Dictionary")
File.CompareMode=1
SettStream=Server.CreateObject("ADODB.Stream")
SetoUpFileStream=Server.CreateObject("ADODB.Stream")
oUpFileStream.Type=1
oUpFileStream.Mode=3
oUpFileStream.Open
oUpFileStream.WriteRequest.BinaryRead(Request.TotalBytes)
oUpFileStream.Position=0
RequestBinDate=oUpFileStream.Read
iFormEnd=oUpFileStream.Size
bCrLf=ChrB(13)&ChrB(10)
'获得每个项目之间的分隔符
sSpace=MidB(RequestBinDate,1,InStrB(1,RequestBinDate,bCrLf)-1)
iStart=LenB(sSpace)
iFormStart=iStart+2
'分解项目
Do
iInfoEnd=InStrB(iFormStart,RequestBinDate,bCrLf&bCrLf)+3
tStream.Type=1
tStream.Mode=3
tStream.Open
oUpFileStream.Position=iFormStart
oUpFileStream.CopyTotStream,iInfoEnd-iFormStart
tStream.Position=0
tStream.Type=2
tStream.CharSet="gb2312"
sInfo=tStream.ReadText
'获得表单项目称号
iFormStart=InStrB(iInfoEnd,RequestBinDate,sSpace)-1
iFindStart=InStr(22,sInfo,"name=""",1)+6
iFindEnd=InStr(iFindStart,sInfo,"""",1)
sFormName=Mid(sinfo,iFindStart,iFindEnd-iFindStart)
'假如是文件
IfInStr(45,sInfo,"filename=""",1)>0Then
SetoFileInfo=newclsFileInfo
'获得文件属性
iFindStart=InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd=InStr(iFindStart,sInfo,""""&vbCrLf,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.FileMIME=Mid(sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileStart=iInfoEnd
oFileInfo.FileSize=iFormStart-iInfoEnd-2
oFileInfo.FormName=sFormName
file.addsFormName,oFileInfo
else
'假如是表单项目
tStream.Close
tStream.Type=1
tStream.Mode=3
tStream.Open
oUpFileStream.Position=iInfoEnd
oUpFileStream.CopyTotStream,iFormStart-iInfoEnd-2
tStream.Position=0
tStream.Type=2
tStream.CharSet="gb2312"
sFormValue=tStream.ReadText
IfForm.Exists(sFormName)Then
Form(sFormName)=Form(sFormName)&","&sFormValue
else
Form.AddsFormName,sFormValue
EndIf
EndIf
tStream.Close
iFormStart=iFormStart+iStart+2
'假如到文件尾了就加入
LoopUntil(iFormStart+2)>=iFormEnd
RequestBinDate=""
SettStream=Nothing
isGetData_=true
endif
EndSub
'保存到文件,主动覆盖已具有的同名文件
PublicFunctionSaveToFile(Item,Path)
SaveToFile=SaveToFileEx(Item,Path,True)
EndFunction
'保存到文件,主动设置文件名
PublicFunctionAutoSave(Item,Path)
AutoSave=SaveToFileEx(Item,Path,false)
EndFunction
'保存到文件,OVER为真时,主动覆盖已具有的同名文件,否则主动把文件改名保存
PrivateFunctionSaveToFileEx(Item,Path,Over)
OnErrorResumeNext
DimoFileStream
DimtmpPath
Dimnohack'防黑缓冲
isErr=0
SetoFileStream=CreateObject("ADODB.Stream")
oFileStream.Type=1
oFileStream.Mode=3
oFileStream.Open
oUpFileStream.Position=File(Item).FileStart
oUpFileStream.CopyTooFileStream,File(Item).FileSize
nohack=split(path,".")'重要修改,防止黑客二进制"01"断名!
!
!
tmpPath=nohack(0)&"."&nohack(ubound(nohack))'重要修改,防止黑客二进制"01"断名!
!
!
ifOverthen
ifisAllowExt(GetFileExt(tmpPath))then
oFileStream.SaveToFiletmpPath,2
Else
isErr_=3
ErrMessage_="该后缀名的文件不答应上传!
"
Endif
Else
Path=GetFilePath(Path)
ifisAllowExt(File(Item).FileExt)then
do
Err.Clear()
nohack=split(Path&GetNewFileName()&"."&File(Item).FileExt,".")'重要修改,防止黑客二进制"01"断名!
!
!
tmpPath=nohack(0)&"."&nohack(ubound(nohack))'重要修改,防止黑客二进制"01"断名!
!
!
oFileStream.SaveToFiletmpPath
loopUntilErr.number<1
oFileStream.SaveToFilePath
Else
isErr_=3
ErrMessage_="该后缀名的文件不答应上传!
"
Endif
Endif
oFileStream.Close
SetoFileStream=Nothing
ifisErr_=3thenSaveToFileEx=""elseSaveToFileEx=GetFileName(tmpPath)
EndFunction
'获得文件数据
PublicFunctionFileData(Item)
isErr_=0
ifisAllowExt(File(Item).FileExt)then
oUpFileStream.Position=File(Item).FileStart
FileData=oUpFileStream.Read(File(Item).FileSize)
Else
isErr_=3
ErrMessage_="该后缀名的文件不答应上传!
"
FileData=""
Endif
EndFunction
'获得文件路径
PublicfunctionGetFilePath(FullPath)
IfFullPath<>""Then
GetFilePath=Left(FullPath,InStrRev(FullPath,"\"))
Else
GetFilePath=""
EndIf
Endfunction
'获得文件名
PublicFunctionGetFileName(FullPath)
IfFullPath<>""Then
GetFileName=mid(FullPath,InStrRev(FullPath,"\")+1)
Else
GetFileName=""
EndIf
Endfunction
'获得文件的后缀名
PublicFunctionGetFileExt(FullPath)
IfFullPath<>""Then
GetFileExt=LCase(Mid(FullPath,InStrRev(FullPath,".")+1))
Else
GetFileExt=""
EndIf
Endfunction
'获得一个不反复的序号
PublicFunctionGetNewFileName()
dimranNum
dimdtNow
dtNow=Now()
ranNum=int(90000*rnd)+10000
GetNewFileName=year(dtNow)&right("0"&month(dtNow),2)&right("0"&day(dtNow),2)&right("0"&hour(dtNow),2)&right("0"&minute(dtNow),2)&right("0"&second(dtNow),2)&ranNum
EndFunction
PublicFunctionisAllowExt(Ext)
ifNoAllowExt=""then
isAllowExt=cbool(InStr(1,";"&AllowExt&";",LCase(";"&Ext&";")))
else
isAllowExt=notCBool(InStr(1,";"&NoAllowExt&";",LCase(";"&Ext&";")))
endif
EndFunction
EndClass
'----------------------------------------------------------------------------------------------------
'文件属性类
ClassclsFileInfo
DimFormName,FileName,FilePath,FileSize,FileMIME,FileStart,FileExt
EndClass
%>
<HTML>
<HEAD>
<STYLETYPE="text/css">
<!
--
.p9{font-size:
9pt;font-family:
宋体}
td{font-size:
9pt}
.tx{height:
16px;width:
30px;border-color:
blackblack#000000;border-top-width:
0px;border-right-width:
0px;border-bottom-width:
1px;border-left-width:
0px;font-size:
9pt;background-color:
#eeeeee;color:
#0000FF}
.tx2{height:
16px;border-top-width:
0px;border-right-width:
0px;border-bottom-width:
1px;border-left-width:
0px;font-size:
9pt;color:
#0000FF;border-left-color:
#000000;border-right-color:
#000000;border-top-color:
#000000;border-bottom-color:
#000000}
.bt{border-left:
1pxsolid#C0C0C0;border-top:
1pxsolid#C0C0C0;font-size:
9pt;border-right-width:
1;border-bottom-width:
1;height:
16px;width:
80px;background-color:
#EEEEEE;cursor:
hand;border-right-style:
solid;border-bottom-style:
solid}
.tx1{width:
400;height:
20px;font-size:
9pt;border:
1pxsolid;border-color:
blackblack#000000;color:
#0000FF}
-->
</STYLE>
<TITLE>上传文件</TITLE>
<METAHTTP-EQUIV="Content-Type"CONTENT="text/html;charset=gb2312">
<SCRIPTLANGUAGE="vbscript">
functionaddfile()
dimstr
str="<table>"
ifnotIsNumeric(window.form1.filenum.value)thenwindow.form1.filenum.value=1
fori=1towindow.form1.filenum.value
str=str&"<tr><tdvalign='middle'>文件"&i&":
</td><td><inputtype='file'name='file"&i&"'class='tx1'valuesize='20'> 保存为<inputtype='text'name='file"&i&"'size='20'class='tx2'></td></tr>"
next
window.uptd.innerHTML=str&a
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- asp 文件 上传
![提示](https://static.bingdoc.com/images/bang_tan.gif)