一款利用asp文件上传组件把文件上传到服务器之前进行判断文件大小否超过指定大小了本实例讲的是upload_xsoft文件上传组件哦filefilesize>就可以限制文件为多少k
dim uploadfileformnameformpathicountfilenamefileext
set upload=new upload_xsoft 建立上传对象
formpath="download/" 在目录后加(/)
if right(formpath)<>"/" then formpath=formpath&"/"
for each formname in uploadfile 列出所有上传了的文件
set file=uploadfile(formname) 生成一个文件对象
if filefilesize> then
message=
else 如果 filesize < 说明有文件数据
fileext=lcase(right(filefilename))
if fileext<>"exe" and fileext<>"zip" and fileext<>"rar" and fileext<>"mxp" then
message=
else
randomize
rannum=int(*rnd)+
filename=formpath& "lemongtree_" & year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rannum&fileext
filesaveas servermappath(filename) 保存文件
if fileext="zip" then
uploadtype = "zip"
elseif fileext="rar" then
uploadtype = "rar"
elseif fileext="mxp" then
uploadtype = "mxp"
elseif fileext="exe" then
uploadtype = "exe"
end if
uploadchar = filename
size = clng(filefilesize)/
message=
end if
end if
next
%>
<% if message= then%>
<html>
<head>
<title>大小超标</title>
<meta httpequiv="contenttype" content="text/html; charset=gb">
<script language=网页特效>
function error_size()
{
alert("文件大小超过kb请重新选择");
windowlocation="uploadasp";
}
</script>
</head>
<body bgcolor="#fff" leftmargin="" topmargin="" onload="error_size()">
</body>
</html>
<% elseif message= then%>
<html>
<head>
<title>类型不匹配</title>
<meta httpequiv="contenttype" content="text/html; charset=gb">
<script language=javascript>
function error_type()
{
alert("只能上传 zip / rar / exe /mxp 文件n请选择正确的文件类型!");
windowlocation="uploadasp";
}
</script>
</head>
<body bgcolor="#fff" leftmargin="" topmargin="" onload="error_type()">
</body>
</html>
<% elseif message= then%>
<html>
<head>
<title>上传成功</title>
<meta httpequiv="contenttype" content="text/html; charset=gb">
<script language=javascript>
function image_success()
{
alert("文件上传成功!");
parentformurlvalue="<%=uploadchar %>"
parentformsizevalue="<%=size%>k"
windowlocation="uploadasp";
}
</script>
</head>
<body bgcolor="#fff" leftmargin="" topmargin="" onload="image_success()">
</body>
</html>
<% end if %>
<%
set file=nothing
set upload=nothing 删除此对象
%>