仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 553|回复: 8
打印 上一主题 下一主题

[学习教程] ASP网站制作之ASP无组件上载,带进度条,多文件上载

[复制链接]
山那边是海 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:19:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
缺点:安全性不是太差了,还行,只要你充分利用系统自带的工具;唯一缺点就是执行效率慢,如何进行网站优化以后,效果会比较好。无组件Example.asp
<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%>
<!--#includefile="SundyUpload.asp"-->
<%
此例子文档编码都是UTF-8,假如是其他编码的体系,请将编码转换为响应的编码,否则表单猎取数据大概会乱码
DimobjUpload,opt
DimxmlPath
DimfileFormName,objFile,counter
opt=request.QueryString("opt")
Ifopt="Upload"Then
xmlPath=Server.MapPath(request.QueryString("xmlPath"))将假造路径转换为实践路径
SetobjUpload=newSundyUpload创建上传工具
objUpload.UploadInitxmlPath,"utf-8"
counter=1
Response.Write("一般表单:"&objUpload.Form("normalForm")&"<BR><BR>")猎取表双数据
ForEachfileFormNameInobjUpload.objFile
SetobjFile=objUpload.objFile(fileFormName)
fileSize=objFile.FileSize
strTemp=objFile.FilePath
Response.WritestrTemp
fileName=mid(strTemp,InStrRev(strTemp,"")+1)
IffileSize>0Then
Response.Write("FileSize:"&fileSize&"<BR>")
Response.Write("FileName:"&objFile.FilePath&"<BR>")
Response.Write("FileDescription:"&objUpload.Form("fileDesc"&counter)&"<BR><BR>")
objFile.SaveAsServer.MapPath(".")&"upload"&fileName
Response.Write"Saveat:"&Server.MapPath(".")&"upload"&fileName&"<br><br>"
EndIf
counter=counter+1
Next

EndIf
为上载进度条数据文件(XML文件指定假造路径)
最好是随机的,由于大概多团体同时上载,必要分歧的进度数据
这个路径必要在提交的时分传进上载组件中,以便在上载过程当中变动进度数据
客户端利用javascript来读取此XML文件,显现进度
xmlPath="upload/"&Timer&".xml"
%>
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>SundyUploadProgressBarExample</title>
<scriptlanguage="javascript">
functionchkFrm(){
varobjFrm=document.frmUpload;
if(objFrm.file1.value==""&&objFrm.file2.value==""){
alert("请选择一个文件");
objFrm.file1.focus();
returnfalse;
}
objFrm.action="Example.asp?opt=Upload&xmlPath=<%=xmlPath%>";
startProgress(<%=xmlPath%>);//启动进度条
returntrue;
}
</script>
</head>
<body>
<formname="frmUpload"method="post"action="Example.asp"enctype="multipart/form-data">
一般表单:<BR><inputtype="text"name="normalForm"size="40"><BR><BR>
文件1:<BR>
<inputtype="file"name="file1"size="40"></br>
<inputtype="text"name="fileDesc1"size="30"><BR><BR>
文件2:<BR>
<inputtype="file"name="file2"size="40"></br>
<inputtype="text"name="fileDesc2"size="30"><BR>
文件3:<BR>
<inputtype="file"name="file3"size="40"></br>
文件4:<BR>
<inputtype="file"name="file4"size="40"></br>
文件5:<BR>
<inputtype="file"name="file5"size="40"></br>
<inputtype="submit"name="btnSubmit"value="submit"/>
</form>
</body>
</html>
SundyUpload.asp
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<%
DimSundyUpload_SourceData
ClassSundyUpload
DimobjForm,objFile,Version,objProgress
DimxmlPath,CharsetEncoding
PublicFunctionForm(strForm)
strForm=lcase(strForm)
IfNOTobjForm.exists(strForm)Then
Form=""
Else
Form=objForm(strForm)
EndIf
EndFunction
PublicFunctionFile(strFile)
strFile=lcase(strFile)
IfNOTobjFile.exists(strFile)Then
SetFile=newFileInfo
Else
SetFile=objFile(strFile)
EndIf
EndFunction

PublicSubUploadInit(progressXmlPath,charset)
DimRequestData,sStart,Crlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
DimiFileSize,sFilePath,sFileType,sFormValue,sFileName
DimiFindStart,iFindEnd
DimiFormStart,iFormEnd,sFormName

Version="UploadWidthProgressBarVersion1.0"
SetobjForm=Server.CreateObject("Scripting.Dictionary")
SetobjFile=Server.CreateObject("Scripting.Dictionary")
IfRequest.TotalBytes<1ThenExitSub
SettStream=Server.CreateObject("adodb.stream")
SetSundyUpload_SourceData=Server.CreateObject("adodb.stream")
SundyUpload_SourceData.Type=1
SundyUpload_SourceData.Mode=3
SundyUpload_SourceData.Open

DimTotalBytes
DimChunkReadSize
DimDataPart,PartSize
DimobjProgress

TotalBytes=Request.TotalBytes总巨细
ChunkReadSize=64*1024分块巨细64K
BytesRead=0
xmlPath=progressXmlPath
CharsetEncoding=charset
IfCharsetEncoding=""Then
CharsetEncoding="utf-8"
EndIf
SetobjProgress=NewProgress
objProgress.ProgressInit(xmlPath)
objProgress.UpdateProgressTotalbytes,0
轮回分块读取
DoWhileBytesRead<TotalBytes
分块读取
PartSize=ChunkReadSize
IfPartSize+BytesRead>TotalBytesThenPartSize=TotalBytes-BytesRead
DataPart=Request.BinaryRead(PartSize)
BytesRead=BytesRead+PartSize

SundyUpload_SourceData.WriteDataPart

objProgress.UpdateProgressTotalbytes,BytesRead
Loop
SundyUpload_SourceData.WriteRequest.BinaryRead(Request.TotalBytes)
SundyUpload_SourceData.Position=0
RequestData=SundyUpload_SourceData.Read

iFormStart=1
iFormEnd=LenB(RequestData)
Crlf=chrB(13)&chrB(10)
sStart=MidB(RequestData,1,InStrB(iFormStart,RequestData,Crlf)-1)
iStart=LenB(sStart)
iFormStart=iFormStart+iStart+1
While(iFormStart+10)<iFormEnd
iInfoEnd=InStrB(iFormStart,RequestData,Crlf&Crlf)+3
tStream.Type=1
tStream.Mode=3
tStream.Open
SundyUpload_SourceData.Position=iFormStart
SundyUpload_SourceData.CopyTotStream,iInfoEnd-iFormStart
tStream.Position=0
tStream.Type=2
tStream.Charset=CharsetEncoding
sInfo=tStream.ReadText
tStream.Close
获得表单项目称号
iFormStart=InStrB(iInfoEnd,RequestData,sStart)
iFindStart=InStr(22,sInfo,"name=""",1)+6
iFindEnd=InStr(iFindStart,sInfo,"""",1)
sFormName=lcase(Mid(sinfo,iFindStart,iFindEnd-iFindStart))
假如是文件
IfInStr(45,sInfo,"filename=""",1)>0Then
SettheFile=newFileInfo
获得文件名
iFindStart=InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd=InStr(iFindStart,sInfo,"""",1)
sFileName=Mid(sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileName=getFileName(sFileName)
theFile.FilePath=getFilePath(sFileName)
获得文件范例
iFindStart=InStr(iFindEnd,sInfo,"Content-Type:",1)+14
iFindEnd=InStr(iFindStart,sInfo,vbCr)
theFile.FileType=Mid(sinfo,iFindStart,iFindEnd-iFindStart)
theFile.FileStart=iInfoEnd
theFile.FileSize=iFormStart-iInfoEnd-3
theFile.FormName=sFormName
IfNOTobjFile.Exists(sFormName)Then
objFile.addsFormName,theFile
EndIf
Else
假如是表单项目
tStream.Type=1
tStream.Mode=3
tStream.Open
SundyUpload_SourceData.Position=iInfoEnd
SundyUpload_SourceData.CopyTotStream,iFormStart-iInfoEnd-3
tStream.Position=0
tStream.Type=2
tStream.Charset=CharsetEncoding
sFormValue=tStream.ReadText
tStream.Close
IfobjForm.Exists(sFormName)Then
objForm(sFormName)=objForm(sFormName)&","&sFormValue
Else
objForm.AddsFormName,sFormValue
EndIf
EndIf
iFormStart=iFormStart+iStart+1
Wend
RequestData=""
SettStream=Nothing
EndSub
PrivateSubClass_Initialize

EndSub

PrivateSubClass_Terminate
IfRequest.TotalBytes>0Then
objForm.RemoveAll
objFile.RemoveAll
SetobjForm=Nothing
SetobjFile=Nothing
SundyUpload_SourceData.Close
SetSundyUpload_SourceData=Nothing
EndIf
SetobjProgress=Nothing
SetobjFso=Server.CreateObject("Scripting.FileSystemObject")
IfobjFso.FileExists(xmlPath)Then
objFso.DeleteFile(xmlPath)
EndIf
SetobjFso=Nothing
EndSub

PrivateFunctionGetFilePath(FullPath)
IfFullPath""Then
GetFilePath=left(FullPath,InStrRev(FullPath,""))
Else
GetFilePath=""
EndIf
EndFunction

PrivateFunctionGetFileName(FullPath)
IfFullPath""Then
GetFileName=mid(FullPath,InStrRev(FullPath,"")+1)
Else
GetFileName=""
EndIf
EndFunction
EndClass
ClassFileInfo
DimFormName,FileName,FilePath,FileSize,FileType,FileStart
PrivateSubClass_Initialize
FileName=""
FilePath=""
FileSize=0
FileStart=0
FormName=""
FileType=""
EndSub

PublicFunctionSaveAs(FullPath)
Dimdr,ErrorChar,i
SaveAs=True
Response.Writefullpath&".....................<br>"
FileName="ss.txt"
Iftrim(fullpath)=""orFileStart=0orfileName=""orright(fullpath,1)="/"ThenExitFunction
Response.Write"2........................<br>"
Setdr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
SundyUpload_SourceData.position=FileStart
SundyUpload_SourceData.copytodr,FileSize
dr.SaveToFileFullPath,2
dr.Close
Setdr=Nothing
SaveAs=False
EndFunction
EndClass
ClassProgress
DimobjDom,xmlPath
DimstartTime
PrivateSubClass_Initialize
EndSub

PublicSubProgressInit(xmlPathTmp)
DimobjRoot,objChild
DimobjPI
xmlPath=xmlPathTmp
SetobjDom=Server.CreateObject("Microsoft.XMLDOM")
SetobjRoot=objDom.createElement("progress")
objDom.appendChildobjRoot

SetobjChild=objDom.createElement("totalbytes")
objChild.Text="0"
objRoot.appendChildobjChild
SetobjChild=objDom.createElement("uploadbytes")
objChild.Text="0"
objRoot.appendChildobjChild
SetobjChild=objDom.createElement("uploadpercent")
objChild.Text="0%"
objRoot.appendChildobjChild
SetobjChild=objDom.createElement("uploadspeed")
objChild.Text="0"
objRoot.appendChildobjChild
SetobjChild=objDom.createElement("totaltime")
objChild.Text="00:00:00"
objRoot.appendChildobjChild
SetobjChild=objDom.createElement("lefttime")
objChild.Text="00:00:00"
objRoot.appendChildobjChild

SetobjPI=objDom.createProcessingInstruction("xml","version=1.0encoding=utf-8")
objDom.insertBeforeobjPI,objDom.childNodes(0)
objDom.SavexmlPath
SetobjPI=Nothing
SetobjChild=Nothing
SetobjRoot=Nothing
SetobjDom=Nothing
EndSub

SubUpdateProgress(tBytes,rBytes)
DimeTime,currentTime,speed,totalTime,leftTime,percent
IfrBytes=0Then
startTime=Timer
SetobjDom=Server.CreateObject("Microsoft.XMLDOM")
objDom.load(xmlPath)
objDom.selectsinglenode("//totalbytes").text=tBytes
objDom.save(xmlPath)
Else
speed=0.0001
currentTime=Timer
eTime=currentTime-startTime
IfeTime>0Thenspeed=rBytes/eTime
totalTime=tBytes/speed
leftTime=(tBytes-rBytes)/speed
percent=Round(rBytes*100/tBytes)
objDom.selectsinglenode("//uploadbytes").text=rBytes
objDom.selectsinglenode("//uploadspeed").text=speed
objDom.selectsinglenode("//totaltime").text=totalTime
objDom.selectsinglenode("//lefttime").text=leftTime
objDom.selectsinglenode("//uploadbytes").text=FormatFileSize(rBytes)&"/"&FormatFileSize(tBytes)
objDom.selectsinglenode("//uploadpercent").text=percent
objDom.selectsinglenode("//uploadspeed").text=FormatFileSize(speed)&"/sec"
objDom.selectsinglenode("//totaltime").text=SecToTime(totalTime)
objDom.selectsinglenode("//lefttime").text=SecToTime(leftTime)
objDom.save(xmlPath)
EndIf
EndSub
privateFunctionSecToTime(sec)
Dimh:h="0"
Dimm:m="0"
Dims:s="0"
h=round(sec/3600)
m=round((secmod3600)/60)
s=round(secmod60)
IfLEN(h)=1Thenh="0"&h
IfLEN(m)=1Thenm="0"&m
IfLEN(s)=1Thens="0"&s
SecToTime=(h&":"&m&":"&s)
EndFunction

privateFunctionFormatFileSize(fsize)
Dimradio,k,m,g,unitTMP
k=1024
m=1024*1024
g=1024*1024*1024
radio=1
IfFix(fsize/g)>0.0Then
unitTMP="GB"
radio=g
ElseIfFix(fsize/m)>0Then
unitTMP="MB"
radio=m
ElseIfFix(fsize/k)>0Then
unitTMP="KB"
radio=k
Else
unitTMP="B"
radio=1
EndIf
Ifradio=1Then
FormatFileSize=fsize&""&unitTMP
Else
FormatFileSize=FormatNumber(fsize/radio,3)&unitTMP
EndIf
EndFunction
PrivateSubClass_Terminate
SetobjDom=Nothing
EndSub
EndClass
http://www.ckuyun.com/
%>
<scriptlanguage="javascript">
//启动进度条
functionstartProgress(xmlPath){
displayProgress();
setProgressDivPos();
setTimeout("DisplayProgressBar("+xmlPath+")",500);
}
functionDisplayProgressBar(xmlPath){
varxmlDoc=newActiveXObject("Msxml2.DOMDocument.3.0");
xmlDoc.async=false;
xmlDoc.load(xmlPath);
if(xmlDoc.parseError.errorCode!=0){
varerror=xmlDoc.parseError;
alert(error.reason)
setTimeout("DisplayProgressBar("+xmlPath+")",1000);
return;
}
varroot=xmlDoc.documentElement;//根节点
vartotalbytes=root.childNodes(0).text;
varuploadbytes=root.childNodes(1).text;
varpercent=root.childNodes(2).text;
ProgressPercent.innerHTML=percent+"%";
ProgressBar.style.width=percent+"%";
uploadSize.innerHTML=uploadbytes;
uploadSpeed.innerHTML=root.childNodes(3).text;
totalTime.innerHTML=root.childNodes(4).text;
leftTime.innerHTML=root.childNodes(5).text;
if(percent<100){
setTimeout("DisplayProgressBar("+xmlPath+")",1000);
}
}
functiondisplayProgress(){
varobjProgress=document.getElementById("Progress");
objProgress.style.display="";
}
functioncloseProgress(){
varobjProgress=document.getElementById("Progress");
objProgress.style.display="none";
}
functionsetProgressDivPos(){
varobjProgress=document.getElementById("Progress");
objProgress.style.top=document.body.scrollTop+(document.body.clientHeight-document.getElementById("Progress").offsetHeight)/2
objProgress.style.left=document.body.scrollLeft+(document.body.clientWidth-document.getElementById("Progress").offsetWidth)/2;
}
</script>
<styletype="text/CSS">
.progress{
position:absolute;
padding:4px;
top:50;
left:400;
font-family:Verdana,Helvetica,Arial,sans-serif;
font-size:12px;
width:250px;
height:100px;
background:#FFFBD1;
color:#3D2C05;
border:1pxsolid#715208;
/*Mozillaproprietary*/
-moz-border-radius:5px;
/*-moz-opacity:0.95;*/
}
.progresstable,.progresstd{
font-size:9pt;
}
.Bar{
width:100%;
height:15px;
background-color:#CCCCCC;
border:1pxinset#666666;
margin-bottom:4px;
}
.ProgressPercent{
font-size:9pt;
color:#000000;
height:15px;
position:absolute;
z-index:20;
width:100%;
text-align:center;
}
.ProgressBar{
background-color:#91D65C;
width:1px;
height:15px;
}
</style>
<divid="Progress"style="display:none;"class="progress">
<divclass="bar">
<divid="ProgressPercent"class="ProgressPercent">0%</div>
<divid="ProgressBar"class="ProgressBar"></div>
</div>
<tableborder="0"cellspacing="0"cellpadding="2">
<tr>
<td>已上传</td>
<td>:</td>
<tdid="uploadSize"></td>
</tr>
<tr>
<td>上传速率</td>
<td>:</td>
<tdid="uploadSpeed"></td>
</tr>
<tr>
<td>共需工夫</td>
<td>:</td>
<tdid="totalTime"></td>
</tr>
<tr>
<td>残剩工夫</td>
<td>:</td>
<tdid="leftTime"></td>
</tr>
</table>
</div>
在实现ERP等高端的ASP应用时,用户需要提供核心的经营资料,需要ASP商有很高的信用度。楼上说交互性不好,太牵强了吧。在微软提供的一套框架中,利用asp做网站,开发效率高,使用人数少,减少不必要的开销。交互性是互动方式,是有开发人员决定的。
沙发
发表于 2015-1-19 08:48:17 | 只看该作者
下面简单介绍一下我学习ASP的方法,希望对想学习ASP的朋友有所帮助...
海妖 该用户已被删除
板凳
发表于 2015-1-28 05:53:48 | 只看该作者
兴趣爱好,那么你无须学编程,申请一个域名和空间,在网上下载一些免费开源的CMS系统,你不用改代码,只须熟悉它们的后台操作,像office一样简单方便,很快就能建一个站点,很多站长都是这样做的
爱飞 该用户已被删除
地板
发表于 2015-2-5 16:55:16 | 只看该作者
跟学别的语言一样,先掌握变量,流程控制语句(就是ifwhileselect)等,函数/过程,数组
金色的骷髅 该用户已被删除
5#
发表于 2015-2-13 01:44:50 | 只看该作者
完全不知道到底自己学的是什么。最后,除了教程里面说的几个例子,还是什么都不会。
小妖女 该用户已被删除
6#
发表于 2015-3-3 12:40:55 | 只看该作者
Application:这个存储服务端的数据,如果不清除,会直到web应用程序结束才清除(例如重启站点)
蒙在股里 该用户已被删除
7#
发表于 2015-3-11 11:11:27 | 只看该作者
Response:从字面上讲是“响应”,因此这个是服务端向客户端发送东西的,例如Response.Write
莫相离 该用户已被删除
8#
发表于 2015-3-18 09:01:55 | 只看该作者
如何学好ASP,以前也有人问过,把回答给你转过来看看能否对你有帮助:
精灵巫婆 该用户已被删除
9#
发表于 2015-3-25 16:14:17 | 只看该作者
ASP主要是用好六个对象,其实最主要的是用好其中两个:response和request,就可以随心所欲地控制网页变换和响应用户动作了。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-12-24 01:33

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表