aspupload文件重命名及上传进度条的解决方法附代码第12页

2018-09-06 12:39

阅读:613

  发现还没有aspupload这个组件的,这两样功能的解决方案,现把我的改进方案写在这里!谢谢
关于aspupload上传组件,文件重命名,进度条的问题解决方案!
共用到4个文件,分别是1.asp,2.asp,bar.asp,framebar.asp
运行第一个文件:1.asp,执行上传操作!
复制代码 代码如下:
<%
进度条
dimSPid,PID,barref
SetUploadProgress=Server.CreateObject(Persits.UploadProgress)
SPid=UploadProgress.CreateProgressID()
PID=PID=&SPid
barref=framebar.asp?to=10&&PID
%>
<SCRIPTlanguage=javascript>
<!--
functionShowProgress()
//加载进度条
{
strAppVersion=navigator.appVersion;
if(document.upfile.filename.value!=)
{
{
winstyle=dialogWidth=375px;dialogHeight:175px;center:yes;status:no;
window.showModelessDialog(<%=barref%>&b=IE,window,winstyle);
}
else
{
window.open(<%=barref%>&b=NN,,width=370,height=165,true);
}
}
returntrue;
}
functionisPic(){
vartemp;
varExtList=.jpg.gif.bmp.png.swf;//客户端,检测文件后缀名,省得上传完成后,才报文件类型错误!
varfilename=upfile.filename.value;
if(ExtList.indexOf(the_ext)==-1){
alert(不是图片,请选择图片文件!);
returnfalse;
}
returntrue;
}
//-->
</SCRIPT>
<html>
<head></head>
<body>
<formmethod=postenctype=multipart/form-dataaction=2.asp?<%=PID%>name=upfileOnSubmit=returnShowProgress();>

选择要上传的文件:<br>
<inputtype=filename=filename><br>
<inputtype=submitvalue=上传onclick=returnisPic()>
</form>

</body>
</html>

2.asp
复制代码 代码如下:
<%

SetUpload=Server.CreateObject(Persits.Upload)

Preventoverwriting
Upload.OverwriteFiles=False

Weusememoryuploads,文件大小限制,单位:b
Upload.SetMaxSize1*1024*1024*1024,true

ifRequest.QueryString(PID)=then
Upload.ProgressID=010D60EB00C5AA4B
else
Upload.ProgressID=Request.QueryString(PID)
endif

OnErrorResumeNext

Savetomemory保存到内存
Upload.Save

IfErr.Number=8Then
Response.Write文件大于1G
EndIf


为使文件不重名,用系统时间+随机数,作为文件名
DimranNum
randomize
ranNum=int(999*rnd)
CreateName=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum
NewName=CreateName
保存文件路径
articlepath=Server.MapPath(upload1)


ForEachFileinUpload.Files
FileExt=Lcase(replace(File.ext,.,))
服务器端判断文件类型,动网论坛的判断方式
IfCheckFileExt(FileExt)=falsethen
Response.write文件格式不正确,或不能为空[<ahref=#onclick=history.go(-1)>重新上传</a>]

else
File.SaveAsarticlepath&/&NewName&File.ext
Response.WriteNewname:&File.FileName&<BR>
EndIf

Next

%>
<%
服务器端判断文件类型,动网论坛的判断方式
PrivateFunctionCheckFileExt(FileExt)

IfFileExt=orIsEmpty(FileExt)Then
CheckFileExt=false
ExitFunction
EndIf
IfLcase(FileExt)=asporLcase(FileExt)=asaorLcase(FileExt)=aspxthen
CheckFileExt=false
ExitFunction
EndIf
IfLcase(FileExt)=giforLcase(FileExt)=jpgorLcase(FileExt)=pngorLcase(FileExt)=swforLcase(FileExt)=bmpthen
CheckFileExt=true
ExitFunction
Else
CheckFileExt=false
EndIf
EndFunction
%>



12下一页阅读全文


评论


亲,登录后才可以留言!