aspupload文件重命名及上传进度条的解决方法附代码第1/2页
程序员文章站
2022-05-18 11:45:44
发现还没有aspupload这个组件的,这两样功能的解决方案,现把我的改进方案写在这里!谢谢 关于aspupload上传组件,文件重命名,进度条的问题解决方案!...
发现还没有aspupload这个组件的,这两样功能的解决方案,现把我的改进方案写在这里!谢谢
关于aspupload上传组件,文件重命名,进度条的问题解决方案!
共用到4个文件,分别是1.asp,2.asp,bar.asp,framebar.asp
运行第一个文件:1.asp,执行上传操作!
<%
'''进度条
dim spid,pid,barref
set uploadprogress = server.createobject("persits.uploadprogress")
spid = uploadprogress.createprogressid()
pid = "pid=" & spid
barref = "framebar.asp?to=10&" & pid
%>
<script language="javascript">
<!--
function showprogress()
//加载进度条
{
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);
}
}
return true;
}
function ispic(){
var temp;
var extlist = ".jpg.gif.bmp.png.swf";//客户端,检测文件后缀名,省得上传完成后,才报文件类型错误!
var filename = upfile.filename.value;
var the_ext = filename.substr(filename.lastindexof(".")+1).tolowercase();
if (extlist.indexof(the_ext)==-1){
alert("不是图片,请选择图片文件!");
return false;
}
return true;
}
//-->
</script>
<html>
<head></head>
<body>
<form method="post"enctype="multipart/form-data"action="2.asp?<% = pid %>"name="upfile"onsubmit="return showprogress();">
选择要上传的文件:<br>
<input type=file name="filename"><br>
<input type=submit value="上传" onclick="return ispic()">
</form>
</body>
</html>
2.asp
<%
set upload = server.createobject("persits.upload")
' prevent overwriting
upload.overwritefiles = false
' we use memory uploads, 文件大小限制 ,单位:b
upload.setmaxsize 1*1024*1024*1024, true
if request.querystring("pid") = "" then
upload.progressid="010d60eb00c5aa4b"
else
upload.progressid=request.querystring("pid")
end if
on error resume next
' save to memory 保存到内存
upload.save
if err.number = 8 then
response.write "文件大于1g"
end if
'为使文件不重名,用系统时间+随机数,作为文件名
dim rannum
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")
for each file in upload.files
fileext=lcase(replace(file.ext,".",""))
'服务器端判断文件类型,动网论坛的判断方式
if checkfileext(fileext)=false then
response.write "文件格式不正确,或不能为空 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
else
file.saveas articlepath & "/" & newname & file.ext
response.write "new name: " & file.filename & "<br>"
end if
next
%>
<%
'服务器端判断文件类型,动网论坛的判断方式
private function checkfileext(fileext)
if fileext="" or isempty(fileext) then
checkfileext=false
exit function
end if
if lcase(fileext)="asp" or lcase(fileext)="asa" or lcase(fileext)="aspx" then
checkfileext=false
exit function
end if
if lcase(fileext)="gif" or lcase(fileext)="jpg" or lcase(fileext)="png" or lcase(fileext)="swf" or lcase(fileext)="bmp" then
checkfileext=true
exit function
else
checkfileext=false
end if
end function
%>
关于aspupload上传组件,文件重命名,进度条的问题解决方案!
共用到4个文件,分别是1.asp,2.asp,bar.asp,framebar.asp
运行第一个文件:1.asp,执行上传操作!
复制代码 代码如下:
<%
'''进度条
dim spid,pid,barref
set uploadprogress = server.createobject("persits.uploadprogress")
spid = uploadprogress.createprogressid()
pid = "pid=" & spid
barref = "framebar.asp?to=10&" & pid
%>
<script language="javascript">
<!--
function showprogress()
//加载进度条
{
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);
}
}
return true;
}
function ispic(){
var temp;
var extlist = ".jpg.gif.bmp.png.swf";//客户端,检测文件后缀名,省得上传完成后,才报文件类型错误!
var filename = upfile.filename.value;
var the_ext = filename.substr(filename.lastindexof(".")+1).tolowercase();
if (extlist.indexof(the_ext)==-1){
alert("不是图片,请选择图片文件!");
return false;
}
return true;
}
//-->
</script>
<html>
<head></head>
<body>
<form method="post"enctype="multipart/form-data"action="2.asp?<% = pid %>"name="upfile"onsubmit="return showprogress();">
选择要上传的文件:<br>
<input type=file name="filename"><br>
<input type=submit value="上传" onclick="return ispic()">
</form>
</body>
</html>
2.asp
复制代码 代码如下:
<%
set upload = server.createobject("persits.upload")
' prevent overwriting
upload.overwritefiles = false
' we use memory uploads, 文件大小限制 ,单位:b
upload.setmaxsize 1*1024*1024*1024, true
if request.querystring("pid") = "" then
upload.progressid="010d60eb00c5aa4b"
else
upload.progressid=request.querystring("pid")
end if
on error resume next
' save to memory 保存到内存
upload.save
if err.number = 8 then
response.write "文件大于1g"
end if
'为使文件不重名,用系统时间+随机数,作为文件名
dim rannum
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")
for each file in upload.files
fileext=lcase(replace(file.ext,".",""))
'服务器端判断文件类型,动网论坛的判断方式
if checkfileext(fileext)=false then
response.write "文件格式不正确,或不能为空 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
else
file.saveas articlepath & "/" & newname & file.ext
response.write "new name: " & file.filename & "<br>"
end if
next
%>
<%
'服务器端判断文件类型,动网论坛的判断方式
private function checkfileext(fileext)
if fileext="" or isempty(fileext) then
checkfileext=false
exit function
end if
if lcase(fileext)="asp" or lcase(fileext)="asa" or lcase(fileext)="aspx" then
checkfileext=false
exit function
end if
if lcase(fileext)="gif" or lcase(fileext)="jpg" or lcase(fileext)="png" or lcase(fileext)="swf" or lcase(fileext)="bmp" then
checkfileext=true
exit function
else
checkfileext=false
end if
end function
%>
1
下一篇: 怎样做陈皮,你还在用老方法吗