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

时间:2021-05-28

发现还没有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!="")
{
if(strAppVersion.indexOf('MSIE')!=-1&&strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1)>4)
{
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;
varthe_ext=filename.substr(filename.lastIndexOf(".")+1).toLowerCase();
if(ExtList.indexOf(the_ext)==-1){
alert("不是图片,请选择图片文件!");
returnfalse;
}
returntrue;
}
//-->
</SCRIPT>
  <html>
  <head></head>
  <body>
  <formmethod="post"enctype="multipart/form-data"action="2.asp?<%=PID%>"name="upfile"OnSubmit="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.Write"Newname:"&File.FileName&"<BR>"
EndIf

Next

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

IfFileExt=""orIsEmpty(FileExt)Then
CheckFileExt=false
ExitFunction
EndIf
IfLcase(FileExt)="asp"orLcase(FileExt)="asa"orLcase(FileExt)="aspx"then
CheckFileExt=false
ExitFunction
EndIf
IfLcase(FileExt)="gif"orLcase(FileExt)="jpg"orLcase(FileExt)="png"orLcase(FileExt)="swf"orLcase(FileExt)="bmp"then
CheckFileExt=true
ExitFunction
Else
CheckFileExt=false
EndIf
EndFunction
%>



12下一页阅读全文

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章