html规定上传文件的大小,如何限制上传文件的大小和类型?

你好,请参考这里:

一款利用asp文件上传组件把文件上传到服务器之前进行判断文件大小否超过指定大小了,本实例讲的是upload_5xsoft文件上传组件哦,file.filesize1000000就可以限制文件为多少k。

dim upload,file,formname,formpath,icount,filename,fileext

set upload=new upload_5xsoft '建立上传对象

formpath=download/ '在目录后加(/)

if right(formpath,1)/ then formpath=formpath&/

for each formname in upload.file '列出所有上传了的文件

set file=upload.file(formname) '生成一个文件对象

if file.filesize1000000 then

message=1

else '如果 filesize 20000 说明有文件数据

fileext=lcase(right(file.filename,4))

if fileext.exe and fileext.zip and fileext.rar and fileext.mxp then

message=2

else

randomize

rannum=int(90000*rnd)+10000

filename=formpath& lemongtree_ & year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&rannum&fileext

file.saveas server.mappath(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(file.filesize)/1000

message=3

end if

end if

next

%

% if message=1 then%

html

head

title大小超标/title

meta http-equiv=content-type content=text/html; charset=gb2312

script language=网页特效

function error_size()

{

alert(文件大小超过1000kb,请重新选择。);

window.location=upload.asp;

}

/script

/head

body bgcolor=#f2f2f2 leftmargin=0 topmargin=0 οnlοad=error_size()

/body

/html

% elseif message=2 then%

html

head

title类型不匹配/title

meta http-equiv=content-type content=text/html; charset=gb2312

script language=javascript

function error_type()

{

alert(只能上传 zip / rar / exe /mxp 文件n请选择正确的文件类型!);

window.location=upload.asp;

}

/script

/head

body bgcolor=#f2f2f2 leftmargin=0 topmargin=0 οnlοad=error_type()

/body

/html

% elseif message=3 then%

html

head

title上传成功/title

meta http-equiv=content-type content=text/html; charset=gb2312

script language=javascript

function image_success()

{

alert(文件上传成功!);

parent.form1.url1.value=%=uploadchar %

parent.form1.size.value=%=size%k

window.location=upload.asp;

}

/script

/head

body bgcolor=#f2f2f2 leftmargin=0 topmargin=0 οnlοad=image_success()

/body

/html

% end if %

%

set file=nothing

set upload=nothing ''删除此对象

%

取消

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值