-
由于本程序太过庞大, 功能过于复杂, shawl.qiu 随时捉虫中.
最新版本 url: http://blog.csdn.net/btbtd/archive/2006/09/30/1309457.aspxshawl.qiu ASP 无组件上传类 1.0 Final 版
-
主要功能:
1.0 final:
支持自定义上传文件类型
支持自定义上传文件的时间间隔, 单位为秒
支持自定义上传文件总大小限制, 单位为Mb
支持自定义单个文件总大小限制, 单位为Kb
支持检测特定文件类型包含恶意代码的功能
1.0 beta:
支持自定义上传N个文件
支持自定义文件名前缀
支持随机自定义文件名后缀
支持任何编码的中文文件名
后续版本待加功能:
暂无合适的功能需要增加.
说明:
为了方便使用, 把表单域也封装进class(类)
接下来的几版, 主要为增加功能, 等到鄙人觉得没有必要再增加功能的时候, 鄙人将会从改进效率入手.
欢迎提供意见, 鄙人 E-Mail: shawl.qiu@gmail.com
Subject: shawl.qiu ASP 无组件上传类 1.0 Final 版
Author: shawl.qiu
Version: 1.0 final 版
Date: 2006-09-30
Blog: http://blog.csdn.net/btbtd
E-Mail: shawl.qiu@gmail.com
版权声明: 本程序允许非商业用途的自由传播, 商业用途使用者必须支付作者著作权费, 人民币壹仟圆整.
目录:
1. shawl.qiu ASP 无组件上传类 1.0 Final 版(cUpload)源代码及演示
2. 上传预览
shawl.qiu
2006-09-30
http://blog.csdn.net/btbtd
1. shawl.qiu ASP 无组件上传类 1.0 Final 版(cUpload)源代码及演示
- linenum
- <%
- dim upload
- set upload=new cUpload
- with upload
- '----------------------------------------
- ' shawl.qiu ASP 无组件上传类 1.0 Final 版
- '----------------------------------------
- .header '头部信息 [非必须]
- '----------------------------------------
- ' 页面设置:
- '--------------------
- .upQueryString=request.queryString("id") '目标查询 ID [必选项]
- .upCharSet="utf-8" '页面编码 [必选项], 请正确设置页面编码!
- '----------------------------------------
- ' 上传文件各参数设置:
- '--------------------
- .upBinaryTotal=cLng(request.TotalBytes) '读取二进制字节长度 [必选项]
- .upPath="/saveimg/" ' 上传文件默认存放路径 [必选项]
- ' 定义允许上传的文件扩展名, 以竖杠分隔("|")多个扩展名 [必选项]
- .upFileNameExtension=".7z|.rar|.zip|.mp3|.bmp|.gif|.jpg|.jpeg|.png|.txt|.swf"
- .upAllowTotalSize=10 '允许上传的总大小, 单位为 MB(megabyte) [非必须]
- .upAllowFileSize=1024 '允许上传的单个文件大小, 单位为 KB(kilobyte) [非必须]
- .upOverWrite=2 ' 上传文件是否覆盖原有文件设置. 1 或空为不覆盖, 2 为覆盖, 默认为 1 [非必须]
- .upTimeInterval=60 ' 允许上传文件的时间间隔, 单位为秒(Session) [非必须]
- .upGoBackSec=60 ' 上传完毕后, 隔 N 秒后返回 [非必须]
- .upCheckFile=".gif|.jpg|.jpeg|.png|.bmp" ' 指定检查是否包含恶意代码的文件类型 [非必须]
- '----------------------------------------
- ' 表单域默认值:
- '--------------------
- ' 提交表单目标地址, 处理上传操作 ID值必须为 upfile, 如 ?xxx=upfile [必选项]
- .upAction="?id=upfile"
- .upNumber= 10 ' 显示上传文件 文件框 数量. 最小为1, 最大为 99, 默认为 1 [非必须]
- .upFileNamePrefix="前缀" ' 自定义文件名前缀, 不想加前缀, 注释掉此项 [非必须]
- .upFileNamePostfix=1 ' 是否添加随机后缀, 空值不添加, 注释掉此项 [非必须]
- '----------------------------------------
- .pgUpFile ' 处理上传文件操作 [必选项]
- .pgUploadInfo ' 表单域内容相关信息及已上传文件相关信息 [非必须]
- .pgUpForm ' 上传文件表单域 [必选项]
- .pgShowAcceptExtension '显示允许上传的文件扩展名 [非必须]
- .pgAcceptSize '显示允许上传总大小值(Mb), 和每文件最大允许值(Kb). [非必须]
- '----------------------------------------
- ' 文件上传操作相关信息:
- 'response.write join(.upFilePathArray,"<br/>") ' 存储所有已上传文件路径的数组 [非必须]
- '.pgShowImage ' 显示已上传的图片文件 [非必须]
- .info ' 功能信息 [非必须]
- .auther ' 作者及版本信息 [非必须]
- '----------------------------------------
- end with
- set upload=nothing
- class cUpload
- private sub class_initialize()
- response.write "<style type=""text/css"">/*<![CDATA[*/"
- response.write "html,body{overflow-x: hidden;}"
- response.write ".cAlCenter{text-align:center!important;}"
- response.write ".cDspTable{distable:table;}"
- response.write ".cDspBlock{distable:block;}"
- response.write ".cCorRed{color:red!important;}"
- response.write ".cW100pc{width:100%;}"
- response.write ".cFtSize28px{font-size:28px;}"
- response.write ".cMrg10px{margin:10px!important;}"
- response.write ".cMrg0px{margin:0px!important;}"
- response.write ".cPad0px{padding:0px!important;}"
- response.write ".cPad10px{padding:10px!important;}"
- response.write ".cPad0px_10px{padding:0px 10px!important;}"
- response.write ".cPad10px_0px{padding:10px 0px!important;}"
- response.write ".cLnHeight120pc{line-height: 120%;}"
- response.write ".cLnHeight150pc{line-height: 150%;}"
- response.write "/*]]>*/</style>"
- upHrf=request.ServerVariables("HTTP_REFERER")
- upShowImageExtension=".jpg|.gif|.png|.jpeg|.bmp"
- upFieldPrxPoxNum=0
- end sub
- private sub class_terminate()
- end sub
- public sub header()
- response.write "<div class=""cAlCenter cDspTable cCorRed cW100pc cFtSize28px"">"
- response.write "shawl.qiu ASP 无组件上传类 1.0 Final 版"
- response.write "</div>"
- end sub
- public sub info()
- response.write "<div class=""cPad10px_0px""><h2 class=""cMrg0px cPad0px"">shawl.qiu ASP 无组件上传类 1.0 Final 版</h2><br/>"
- response.write "主要功能:<br/>"
- response.write "1.0 final:<br/><font class=""cCorRed"">"
- response.write "支持自定义上传文件类型<br/>"
- response.write "支持自定义上传文件的时间间隔, 单位为秒<br/>"
- response.write "支持自定义上传文件总大小限制, 单位为Mb<br/>"
- response.write "支持自定义单个文件总大小限制, 单位为Kb<br/>"
- response.write "支持检测特定文件类型包含恶意代码的功能<br/></font>"
- response.write "1.0 beta:<br/><font class=""cCorRed"">"
- response.write "支持自定义上传N个文件<br/>"
- response.write "支持自定义文件名前缀<br/>"
- response.write "支持随机自定义文件名后缀<br/>"
- response.write "支持任何编码的中文文件名<br/></font>"
- response.write "<p/>后续版本待加功能:<br/><font class=""cCorRed"">"
- response.write "暂无合适的功能需要增加.</font>"
- response.write "<p/>说明:<br/><font class=""cCorRed"">"
- response.write "为了方便使用, 把表单域也封装进class(类)<br/>"
- response.write "接下来的几版, 主要为增加功能, 等到鄙人觉得没有必要再增加功能的时候, 鄙人将会从改进效率入手.<br/>"
- response.write "欢迎提供意见, 鄙人 E-Mail: <a href=""mailto:shawl.qiu@gmail.com"">shawl.qiu@gmail.com</a></font>"
- response.write "</div>"
- end sub
- public sub auther()
- response.write "<div class=""cPad10px_0px"">"
- response.write "Subject: shawl.qiu ASP 无组件上传类 1.0 Final 版<br/>"
- response.write "Author: shawl.qiu<br/>"
- response.write "Version: 1.0 final 版<br/>"
- response.write "Date: 2006-09-30<br/>"
- response.write "Blog: <a href="" http://blog.csdn.net/btbtd"" target=""_blank""> http://blog.csdn.net/btbtd</a><br/>"
- response.write "E-Mail: <a href=""mailto:shawl.qiu@gmail.com"">shawl.qiu@gmail.com</a><p/>"
- response.write "版权声明: 本程序允许非商业用途的自由传播, 商业用途使用者必须支付作者著作权费, 人民币壹仟圆整."
- response.write "</div>"
- end sub
- public upQueryString, upCharSet
- public upAction, upNumber, upFileNamePrefix, upFileNamePostfix
- public upPath, upOverWrite, upBinaryTotal
- public upFilePathArray, upFileNameExtension
- public upTimeInterval
- public upAllowTotalSize, upAllowFileSize
- public upGoBackSec
- public upCheckFile
- private upTotalFiled, upAvailableField, upFileUploaded, upFileUploadingTotal
- private upSourceNameArray, upRenamedArray
- private upShowImageExtension
- private upAllFileNameArray, upAbortUploadTotal, upUploadedFileNameArray
- private upHrf
- private upOutsizeDescArray, upOutsizeFilenameArray
- private upFileInvalidDescArray, upFileInvalidArray
- private upUploadedFileSize
- private upAbortFileArray
- private upFieldPrxPoxNum
- public property get pgUploadInfo
- dim upFileUploadingTotalTemp, upAbortFileArrayTemp, upOutsizeDescArrayTemp, upFileInvalidDescArrayTemp
- dim upAvailableFieldTemp: upAvailableFieldTemp=0
- if upBinaryTotal<1 then exit property
- if upFileUploaded="" then upFileUploaded=0
- if upFileUploadingTotal="" then upFileUploadingTotal=0
- if isArray(upAbortFileArray) then upAbortFileArrayTemp=uBound(upAbortFileArray)+1 else upAbortFileArrayTemp=0
- if isArray(upOutsizeDescArray) then upOutsizeDescArrayTemp=uBound(upOutsizeDescArray)+1 else upOutsizeDescArrayTemp=0
- if isArray(upFileInvalidDescArray) then upFileInvalidDescArrayTemp=uBound(upFileInvalidDescArray)+1 else upFileInvalidDescArrayTemp=0
- if upNumber="" then upNumber=1
- upFileUploadingTotalTemp=upFileUploaded+upAbortFileArrayTemp+upOutsizeDescArrayTemp+upFileInvalidDescArrayTemp
- upAvailableFieldTemp=upAvailableFieldTemp+upFileUploadingTotalTemp
- if upFileUploadingTotalTemp<1 then exit property
- response.write "<p/>表单域共有 "&upNumber+2&"个 Field, "
- response.write "可用 Field "&upFileUploadingTotalTemp+upFieldPrxPoxNum&"个, "
- response.write "总上传文件数 "&upFileUploadingTotalTemp&"个, "
- response.write "已上传文件数 "&upFileUploaded&"个. <br/>"
- response.write "本次上传数据总大小约: "&round(upBinaryTotal/1024)&" Kb, 约合 "&_
- round(upBinaryTotal/1024/1024)&" Mb."
- if upFileUploaded>0 then
- dim i
- for i=0 to upFileUploaded-1
- response.write "<p/>文件 "&i+1&" 原文件名: <font class=""cCorRed"">"&upSourceNameArray(i)&"</font><br/>"
- response.write "上传后文件名:<font class=""cCorRed""> "&upRenamedArray(i)&"</font><br/>"
- response.write "文件路径: <a href="""&upFilePathArray(i)&""" target=""_blank"">"&upFilePathArray(i)&"</a></font><br/>"
- response.write "文件大小: <font class=""cCorRed"">"&upUploadedFileSize(i)&"</font>"
- next
- end if
- upAbortUploadTotal=upFileUploadingTotal-upFileUploaded
- if upAbortFileArrayTemp>0 then
- response.write "<p/>被禁止上传的文件扩展名 有 "&upAbortFileArrayTemp&"个:"
- response.write "<font class=""cCorRed"">"
- dim temp
- dim temp_:temp_=1
- for each temp in upAbortFileArray
- response.write "<br/>文件 "&temp_&" : "&temp
- temp_=temp_+1
- next
- response.write "</font>"
- end if
- if isArray(upOutsizeDescArray) then
- response.write "<p/>超出单文件大小("&upAllowFileSize&"Kb)限制的文件有 "&uBound(upOutsizeDescArray)+1
- response.write "个: <br/><font class=""cCorRed"">"
- response.write join(upOutsizeDescArray,"<br/>")
- response.write "</font>"
- end if
- if isArray(upFileInvalidDescArray) then
- response.write "<p/>检测到包含恶意代码的文件有 "&uBound(upFileInvalidDescArray)+1
- response.write "个, 已被禁止上传: <br/><font class=""cCorRed"">"
- response.write join(upFileInvalidDescArray,"<br/>")
- response.write "</font>"
- end if
- pgUploadInfo=pgUploadInfo
- end property
- public property get pgUpFile
- pgUpFile=fOperate(upBinaryTotal)
- end property
- public property get pgUpForm
- pgUpForm=upForm(upAction, upNumber, upFileNamePrefix, upFileNamePostfix)
- end property
- public property get pgShowAcceptExtension
- response.write " 允许上传的文件类型: "
- response.write upFileNameExtension
- end property
- public property get pgAcceptSize
- if upAllowFileSize="" and upAllowFileSize="" then exit property
- response.write "<br/>"
- if upAllowFileSize<>"" then
- response.write "每次上传最大值为 "
- response.write upAllowTotalSize
- response.write "Mb"
- end if
- if upAllowFileSize<>"" then
- response.write " | 每个文件允许的最大值为 "
- response.write upAllowFileSize
- response.write "Kb"
- end if
- response.write "<br/>"
- end property
- public property get pgShowImage
- pgShowImage=upShowImage(upShowImageExtension, upFilePathArray)
- end property
- private function upShowImage(extension, filepath_)
- if not isArray(upFilePathArray) then exit function
- dim extAr:extAr=split(extension,"|")
- dim temp, temp_
- for each temp in upFilePathArray
- for each temp_ in extAr
- if strComp(mid(temp,inStrRev(temp,".")),temp_,1)=0 then
- response.write "<a href="""
- response.write temp
- response.write """ target=""_blank""><img src="""
- response.write temp
- response.write """ alt=""shawl.qiu upload"" title=""shawl.qiu upload""/></a>"
- end if
- next
- next
- end function
- private function fOperate(upBinaryTotal)
- if upBinaryTotal=0 or upBinaryTotal="" then exit function
- if upQueryString<>"upfile" or upAction="" then exit function
- if upFileNameExtension="" then exit function
- if upAllowTotalSize<>"" and isNumeric(upAllowTotalSize) and upAllowTotalSize>0 then
- dim upAllowTotalSizeTemp:upAllowTotalSizeTemp=upAllowTotalSize*1014*1024
- if upAllowTotalSizeTemp<upBinaryTotal then
- response.write "<div class=""cAlCenter cDspTable cW100pc cPad10px cLnHeight120pc"">上传文件总大小为 "&_
- formatNumber(upBinaryTotal,0)
- response.write "字节, 约 "&formatNumber(fix(upBinaryTotal/1024),0)&"Kb/"&fix(upBinaryTotal/1024/1024)&"Mb<br/>"
- response.write "超过 "&formatNumber(upAllowTotalSizeTemp,0)&"字节/"&formatNumber(upAllowTotalSizeTemp/1024,0)&"Kb/"
- response.write upAllowTotalSize&"Mb 的限制, 此次上传被终止"
- if upGoBackSec="" then upGoBackSec=0
- if upGoBackSec>0 then
- response.write fPmt("<p/>"&upGoBackSec&" 秒后 "&fGoBack("返回")&" 还有 ", upGoBackSec, "", upHrf)
- end if
- response.write "</div>"
- exit function
- end if
- end if
- if upTimeInterval<>"" and isNumeric(upTimeInterval) and upTimeInterval>0 then
- dim tInterval
- if session("timestamp")="" then session("timestamp")=now()
- tInterval=dateDiff("s",now(),session("timestamp"))
- if tInterval>0 then
- response.write "<div class=""cAlCenter cW100pc cPad10px cLnHeight150pc"">每次上传文件的时间间隔为 "
- response.write upTimeInterval&"秒, 请稍后再操作. "&fGoBack("返回")&"<br/>"
- call fPmt(" 还有 ", tInterval, " 后才可以再次上传.", upHrf)
- response.write "</div>"
- exit function
- else
- session("timestamp")=dateAdd("s",upTimeInterval,now())
- end if
- end if
- if upOverWrite="" then upOverWrite=1
- if upOverWrite<1 or upOverWrite>2 then upOverWrite=1
- dim lf:lf=chrB(13)&chrB(10)
- dim bRead ' 读取二进制流内容
- bRead=request.BinaryRead(upBinaryTotal)
- dim fieldMarker ' 定义取二进制流 Field 分隔标记 (内容为二进制)
- fieldMarker=leftB(bRead,inStrB(bRead,chrB(13))-1)
- dim headerMarker:headerMarker=leftB(bRead,instrB(bRead,chrB(32))-1)
- dim temp:temp=1
- dim temp_
- dim temp1
- dim temp1_
- dim headerTotal
- dim headerAvailable:headerAvailable=0
- dim headerStartPsti, headerEndPsti, headerStr
- dim fieldStartPsti, fieldEndPsti
- dim fnPrefix, fnPostfix
- do
- temp_=inStrB(temp, bRead, headerMarker)
- if temp_<>0 then
- temp=temp_+1
- temp1=inStrB(temp, bRead, lf&lf)
- temp1_=inStrB(temp1+5, bRead, fieldMarker)
- headerTotal=headerTotal+1
- if inStrB(midB(bRead, temp1+4, 36),midB(fieldMarker,1))=0 then
- if isArray(headerStartPsti) then redim preserve headerStartPsti(headerAvailable) _
- else redim headerStartPsti(headerAvailable)
- headerStartPsti(headerAvailable)=temp-1
- if isArray(headerEndPsti) then redim preserve headerEndPsti(headerAvailable) else _
- redim headerEndPsti(headerAvailable)
- headerEndPsti(headerAvailable)=temp1+2-temp
- if isArray(headerStr) then redim preserve headerStr(headerAvailable) else redim _
- headerStr(headerAvailable)
- headerStr(headerAvailable)=fBin2Str(midB(bRead,temp-1,temp1+2-temp),upCharSet)
- if isArray(fieldStartPsti) then redim preserve fieldStartPsti(headerAvailable) else redim fieldStartPsti(headerAvailable)
- fieldStartPsti(headerAvailable)=temp1
- if isArray(fieldEndPsti) then redim preserve fieldEndPsti(headerAvailable) else redim fieldEndPsti(headerAvailable)
- fieldEndPsti(headerAvailable)=temp1_
- if inStr(headerStr(headerAvailable),"filename")=0 and inStr(headerStr(headerAvailable),"; name=")<>0 then
- select case fRegExpSgl(headerStr(headerAvailable),true,true,true,"[/s/S]*?name/=/""(.*?)""[/s/S]*","$1")
- case "fnPrefix"
- if upCharSet="gb2312" then
- fnPrefix=bTsGb2312(midB(bRead,temp1,temp1_-temp1))
- else
- fnPrefix=fBin2Str(midB(bRead,temp1,temp1_-temp1), upCharSet)
- end if
- case "fnPostfix"
- if upCharSet="gb2312" then
- fnPostfix=bTsGb2312(midB(bRead,temp1,temp1_-temp1))
- else
- fnPostfix=fBin2Str(midB(bRead,temp1,temp1_-temp1), upCharSet)
- end if
- end select
- end if
- headerAvailable=headerAvailable+1
- end if
- else
- exit do
- end if
- loop
- upTotalFiled=headerTotal
- upAvailableField=headerAvailable
- dim fileName, fileNamePrx, fileNamePox
- dim i, i_:i_=0
- dim i1:i1=0
- dim i1_:i1_=0
- dim fileNmaeSaveing
- dim temp2
- dim temp3
- dim temp4:temp4=0
- dim upFieldPrxPoxNumTemp
- if upCheckFile<>"" then
- upCheckFile=split(upCheckFile,"|")
- dim checkAspMark, checkAspMark_
- checkAspMark=chrB(60)&chrB(37) '<%
- checkAspMark_=chrB(37)&chrB(62) '%/>
- dim checkScriptMark, checkScriptMark_ , checkScriptMark__
- checkScriptMark=chrB(115)&chrB(99)&chrB(114)&chrB(105)&chrB(112)&chrB(116)
- checkScriptMark_=chrB(83)&chrB(99)&chrB(114)&chrB(105)&chrB(112)&chrB(116)
- checkScriptMark__=chrB(83)&chrB(67)&chrB(82)&chrB(73)&chrB(80)&chrB(84)
- end if
- for i=0 to uBound(headerStr)
- if inStr(headerStr(i),"fnPrefix")<>0 or inStr(headerStr(i),"fnPostfix")<>0 then
- upFieldPrxPoxNumTemp=fBin2Str(midB(bRead,fieldStartPsti(i)+3,fieldEndPsti(i)-fieldStartPsti(i)-3),upCharSet)
- upFieldPrxPoxNumTemp=fRegExpSgl(upFieldPrxPoxNumTemp,true,true,true,"[/s]+","")
- if upFieldPrxPoxNumTemp<>"" then
- upFieldPrxPoxNum=upFieldPrxPoxNum+1
- end if
- end if
- if inStr(headerStr(i),"filename=")<>0 then
- fileName=fRegExpSgl(headerStr(i),true,true,true,"[/s/S]*filename/=""(.*?)""[/s/S]*","$1")
- if inStrRev(fileName,"/")<>0 then fileName=mid(fileName,inStrRev(fileName,"/")+1)
- fileNamePrx=fRegExpSgl(fileName,true,true,true,"(.*?)/..*","$1")
- fileNamePox=fRegExpSgl(fileName,true,true,true,".*(/..*)","$1")
- if isArray(upAllFileNameArray) then redim preserve upAllFileNameArray(i) else redim upAllFileNameArray(i)
- upAllFileNameArray(i)=fileName
- if inStr(1,upFileNameExtension,fileNamePox,1)=0 then
- if isArray(upAbortFileArray) then redim preserve upAbortFileArray(temp4) else redim upAbortFileArray(temp4)
- upAbortFileArray(temp4)=fileName
- temp4=temp4+1
- end if
- for each temp2 in split(upFileNameExtension,"|")
- if strComp(temp2,fileNamePox,1)=0 then
- if upAllowFileSize<>"" and upAllowFileSize>0 and isNumeric(upAllowFileSize) then
- dim upFileSize:upFileSize=fieldEndPsti(i)-fieldStartPsti(i)-3
- dim upAllowFileSizeTemp:upAllowFileSizeTemp=upAllowFileSize*1024
- if upAllowFileSizeTemp<upFileSize then
- if isArray(upOutsizeDescArray) then redim preserve upOutsizeDescArray(i1) else redim _
- upOutsizeDescArray(i1)
- upOutsizeDescArray(i1)="文件 "&i1+1&": "&fileName&" -|- "&round(upFileSize/1024)&" Kb"
- if isArray(upOutsizeFilenameArray) then redim preserve upOutsizeFilenameArray(i1) else _
- redim upOutsizeFilenameArray(i1)
- upOutsizeFilenameArray(i1)=fileName
- i1=i1+1
- exit for
- end if
- end if
- if isArray(upCheckFile) then
- temp3=midB(bRead,fieldStartPsti(i)+3,fieldEndPsti(i)-fieldStartPsti(i)-3)
- if (inStrB(1, temp3, checkAspMark, 1)<>0 and inStrB(1, temp3, checkAspMark_, 1)<>0) or _
- inStrB(1, temp3, checkScriptMark, 0)<>0 or inStrB(1, temp3, checkScriptMark_, 0)<>0 _
- or inStrB(1, temp3, checkScriptMark__, 0)<>0 then
- if isArray(upFileInvalidDescArray) then redim preserve upFileInvalidDescArray(i1_) else redim _
- upFileInvalidDescArray(i1_)
- upFileInvalidDescArray(i1_)="文件 "&i1_+1&": "&fileName
- if isArray(upFileInvalidArray) then redim preserve upFileInvalidArray(i1_) else redim _
- upFileInvalidArray(i1_)
- upFileInvalidArray(i1_)=fileName
- i1_=i1_+1
- exit for
- end if
- end if
- if isArray(upSourceNameArray) then redim preserve upSourceNameArray(i_) else redim upSourceNameArray(i_)
- upSourceNameArray(i_)=fileName
- if isArray(upUploadedFileNameArray) then redim preserve upUploadedFileNameArray(i_) else redim upUploadedFileNameArray(i_)
- upUploadedFileNameArray(i_)=fileName
- if fnPrefix<>"" then fileNamePrx=fnPrefix&fileNamePrx
- if fnPostfix<>"" then fileNamePrx=fileNamePrx&fGuid
- fileName=fileNamePrx&fileNamePox
- fileName=fRegExpSgl(fileName,true,true,true,"[/s]+","")
- if isArray(upRenamedArray) then redim preserve upRenamedArray(i_) else redim upRenamedArray(i_)
- upRenamedArray(i_)=fileName
- if isArray(upFilePathArray) then redim preserve upFilePathArray(i_) else redim upFilePathArray(i_)
- upFilePathArray(i_)=upPath&fileName
- if isArray(upUploadedFileSize) then redim preserve upUploadedFileSize(i_) else redim upUploadedFileSize(i_)
- upUploadedFileSize(i_)=round(upFileSize/1024)&" Kb"
- call fBinSv2fl(bRead,fieldStartPsti(i)+3,fieldEndPsti(i)-fieldStartPsti(i)-3, upPath&fileName, upOverWrite)
- upFileUploaded=upFileUploaded+1
- i_=i_+1
- end if
- next
- upFileUploadingTotal=upFileUploadingTotal+1
- end if
- next
- if upGoBackSec="" then upGoBackSec=0
- if upGoBackSec>0 then
- response.write fPmt("<div class=""cAlCenter cW100pc cPad10px cLnHeight150pc"">操作已完毕"&_
- ", "&upGoBackSec&" 秒后 "&fGoBack("返回")&"<br/>还有 ", upGoBackSec, "</div>", upHrf)
- end if
- end function
- private function fBinSv2fl(bin, bStart, bEnd, filepath_, ovWrite)
- '--------------------------------------
- ' 截取二进制流保存为文件 By shawl.qiu
- ' http://blog.csdn.net/btbtd
- '---------------------------
- ' sample call: call fBinSv2fl(bRead,fieldStartPsti(i)+3,fieldEndPsti(i)-fieldStartPsti(i)-3, fileName, 2)
- '------------
- ' 参数说明:
- '---------
- ' bin: 源二进制流
- ' bStart: 截取二进制流的起始位置
- ' bEnd: 截取二进制流的结束位置
- ' filepath_: 保存文件的路径
- ' ovWrite: 是否覆盖原有文件. 1: 不覆盖; 2. 覆盖
- '--------------------------------------
- filepath_=server.MapPath(filepath_)
- dim stm_, fromStm_
- set stm_=createObject("adodb.stream")
- stm_.type=1
- stm_.mode=3
- stm_.open
- stm_.write bin
- set fromStm_=createOBject("adodb.stream")
- with fromStm_
- .type=1
- .mode=3
- .open
- stm_.position = bStart
- stm_.copyTo fromStm_, bEnd
- .saveTofile filepath_, ovWrite
- .close
- end with
- set fromStm_=nothing
- stm_.close 'shawl.qiu code'
- set stm_=nothing
- end function
- private function fStr2Bin(str, charSet)
- '--------------------------------------
- ' 字符串转二进制函数 By shawl.qiu
- ' http://blog.csdn.net/btbtd
- '---------------------------
- ' 参数说明:
- '----------
- ' str: 要转换成二进制的字符串
- ' charSet: 字符串默认编码集, 如不指定, 则默认为 gb2312
- '---------------
- ' sample call: response.binaryWrite fStr2Bin(str, "utf-8")
- '--------------------------------------
- dim stm_
- set stm_=createObject("adodb.stream")
- with stm_
- .type=2
- if charSet<>"" then
- .charSet=charSet
- else
- .charSet="gb2312"
- end if
- .open
- .writeText str
- .Position = 0
- .type=1
- fStr2Bin=.Read
- .close
- end with 'shawl.qiu code'
- set stm_=nothing
- end function
- private function fBin2Str(str, charSet)
- '--------------------------------------
- ' 二进制转字符串函数 By shawl.qiu
- ' http://blog.csdn.net/btbtd
- '--------------------------
- ' 参数说明:
- '----------
- ' str: 要转换成字符串的二进制数据
- ' charSet: 字符串默认编码集, 如不指定, 则默认为 gb2312
- '-------------
- ' sample call: response.write fBin2Str(midB(fStr2Bin(str, "utf-8"),1),"utf-8")
- '--------------------------------------
- ' 注意: 二进制字符串必须先用 midB(binaryString,1) 读取(可自定读取长度).
- '--------------------------------------
- dim stm_
- set stm_=createObject("adodb.stream")
- with stm_
- .type=2
- .open
- .writeText str
- .Position = 0
- if charSet<>"" then
- .CharSet = charSet
- else
- .CharSet = "gb2312"
- end if
- fBin2Str=.ReadText
- .close
- end with 'shawl.qiu code'
- set stm_=nothing
- end function
- private function bTsGb2312(bin)
- '二进制转为 string | gb2312 编码
- dim i, iByt, sByt, bLen:bLen=lenB(bin)
- for i=1 to bLen
- sByt=midB(bin,i,1):iByt=ascB(sByt)
- if iByt<128 then
- bTsGb2312=bTsGb2312&chr(iByt)
- else
- bTsGb2312=bTsGb2312&chr(ascW(midB(bin,i+1,1)&sByt))
- i=i+1
- end if
- next 'shawl.qiu code'
- end function
- private function fRegExpSgl(str,glb,igc,mtl,pt,rpt)
- dim re
- set re=new RegExp
- re.global=glb
- re.ignoreCase=igc
- re.multiline=mtl
- re.pattern=pt
- fRegExpSgl=re.replace(str,rpt)
- set re=nothing
- end function 'shawl.qiu code'
- private function fGuid
- fGuid=mid(cstr(createObject("scriptlet.typeLib").GUID),2,36)
- end function 'shawl.qiu code'
- private function upForm(upAction, upNumber, upFileNamePrefix, upFileNamePostfix)
- '-------------------------------------------
- ' shalw.qiu ASP 无组件上传类, 表单域
- '-----------------------------------
- ' sample call: call upForm("?id=test", 5, "文件前缀", "")
- '-------------------------------------------
- if upNumber="" then upNumber=1
- if upNumber<1 or upNumber>99 then upNumber=5
- if upFileNamePostfix<>"" then upFileNamePostfix=" checked=""checked"" "
- dim i_
- response.write "<form action="""&upAction&""" method=""post"""&_
- " enctype=""multipart/form-data"" name=""upForm"" id=""upForm"">"
- for i_=1 to upNumber
- response.write "<div class=""upBrowser""><input type=""file"" name=""file"" "&_
- "class=""upButton"" /> </div>"
- next
- response.write "<div class=""upPrefix"">自定义前缀: <input name=""fnPrefix"" type=""text"""&_
- " value="""&upFileNamePrefix&""" class=""upPrefixButton""/></div>"
- response.write "<div class=""upPostfix"">添加随机后缀: <input name=""fnPostfix"" "&_
- "type=""checkbox"" value=""checkbox"""& upFileNamePostfix&"class=""upPostfixButton"" /> </div>"
- response.write " <input type=""submit"" value=""Submit"" class=""upSubmit"" />"
- response.write "</form>"
- end function
- private function fPmt(prefix, second, postfix, url)
- '---------------------------------------------------
- ' ASP N 秒后转到 XXX 页 函数 By shawl.qiu
- '---------------------------
- ' call fPmt("还有 ",20," 转到首页 ","/")
- '--------------------
- ' 注: 脚本参考自 CSDN Blog 出错页
- '---------------------------------------------------
- response.write "<script type=""text/javascript"">"&vbcrlf
- response.write "//<![CDATA["&vbcrlf
- response.write " var go="&second&"000;"&vbcrlf
- response.write " var timer=null;"&vbcrlf
- response.write " var endTime = new Date().getTime() + go ;"&vbcrlf
- response.write " function interval() {"&vbcrlf
- response.write " var n=(endTime-new Date().getTime())/1000;"&vbcrlf
- response.write " if(n<0) return;"&vbcrlf
- response.write " document.getElementById(""jumpTo"").innerHTML = n.toFixed(3);"&vbcrlf
- response.write " setTimeout(interval, 10);"&vbcrlf
- response.write " }"&vbcrlf
- response.write " window.οnlοad=function(){"&vbcrlf
- response.write " timer=setTimeout(""window.location.href='"&url&"'"", go);"&vbcrlf
- response.write " interval();"&vbcrlf
- response.write " }"&vbcrlf
- response.write "//]]>"&vbcrlf
- response.write "</script>"&vbcrlf
- response.write "<div class=""absltMid"" ><meta http-equiv=""refresh"" content="""
- response.write second
- response.write ";URL="
- response.write url
- response.write """>"
- response.write prefix
- response.write "<span id=""jumpTo"">"&second&".000</span>秒"
- response.write postfix
- response.write "</div>" 'shawl.qiu code'
- end function
- private function fGoBack(prompt)
- dim hrf:hrf=request.ServerVariables("HTTP_REFERER")
- fGoBack="<a href="""&hrf&""">"&prompt&"</a>"
- end function
- end class
- %>
- <a href="">back</a>
2. 上传预览
-
shawl.qiu ASP 无组件上传类 1.0 Final 版<script type="text/javascript"> // </script>
每次上传最大值为 10Mb | 每个文件允许的最大值为 1024Kb
表单域共有 12个 Field, 可用 Field 12个, 总上传文件数 10个, 已上传文件数 5个.
本次上传数据总大小约: 2220 Kb, 约合 2 Mb.文件 1 原文件名: a.bmp
上传后文件名: 前缀aCD5C0B4D-5DD4-4F07-AD2F-531C5F606526.bmp
文件路径: /saveimg/前缀aCD5C0B4D-5DD4-4F07-AD2F-531C5F606526.bmp
文件大小: 576 Kb文件 2 原文件名: b.gif
上传后文件名: 前缀b4669CC12-13B5-4ACE-B026-D5DA1C3D90DD.gif
文件路径: /saveimg/前缀b4669CC12-13B5-4ACE-B026-D5DA1C3D90DD.gif
文件大小: 7 Kb文件 3 原文件名: b.jpg
上传后文件名: 前缀bCA734C87-0B5C-426F-BA36-8B1768669624.jpg
文件路径: /saveimg/前缀bCA734C87-0B5C-426F-BA36-8B1768669624.jpg
文件大小: 4 Kb文件 4 原文件名: b.png
上传后文件名: 前缀b3FFA8EC5-2001-4DDC-BCFE-3572E7EE13E4.png
文件路径: /saveimg/前缀b3FFA8EC5-2001-4DDC-BCFE-3572E7EE13E4.png
文件大小: 3 Kb文件 5 原文件名: 63.rar
上传后文件名: 前缀63FDABF757-DD1E-4065-BD35-B7DD2E40D98F.rar
文件路径: /saveimg/前缀63FDABF757-DD1E-4065-BD35-B7DD2E40D98F.rar
文件大小: 13 Kb被禁止上传的文件扩展名 有 2个:
文件 1 : New Microsoft Excel 工作表.xls
文件 2 : New Microsoft Word 文档.doc超出单文件大小(1024Kb)限制的文件有 1个:
文件 1: Oh_Canada.mp3 -|- 1577 Kb检测到包含恶意代码的文件有 2个, 已被禁止上传:
文件 1: c.gif
文件 2: d.gifshawl.qiu ASP 无组件上传类 1.0 Final 版
主要功能:
1.0 final:
支持自定义上传文件类型
支持自定义上传文件的时间间隔, 单位为秒
支持自定义上传文件总大小限制, 单位为Mb
支持自定义单个文件总大小限制, 单位为Kb
支持检测特定文件类型包含恶意代码的功能
1.0 beta:
支持自定义上传N个文件
支持自定义文件名前缀
支持随机自定义文件名后缀
支持任何编码的中文文件名
后续版本待加功能:
暂无合适的功能需要增加.说明:
为了方便使用, 把表单域也封装进class(类)
接下来的几版, 主要为增加功能, 等到鄙人觉得没有必要再增加功能的时候, 鄙人将会从改进效率入手.
欢迎提供意见, 鄙人 E-Mail: shawl.qiu@gmail.comSubject: shawl.qiu ASP 无组件上传类 1.0 Final 版back
Author: shawl.qiu
Version: 1.0 final 版
Date: 2006-09-30
Blog: http://blog.csdn.net/btbtd
E-Mail: shawl.qiu@gmail.com版权声明: 本程序允许非商业用途的自由传播, 商业用途使用者必须支付作者著作权费, 人民币壹仟圆整.
-
主要功能:
shawl.qiu ASP 无组件上传类 1.0 Final 版
最新推荐文章于 2019-08-25 22:23:55 发布