asp限制上傳文件大小實(shí)例_ASP教程
推薦:一個(gè)實(shí)用asp分頁函數(shù)分享一個(gè)asp分頁函數(shù),感覺挺好看的。視圖如圖: 可以根據(jù)自己的情況修改,代碼: % '謝亮修分頁程序 'call pagecontrol(記錄總數(shù),頁碼總數(shù),當(dāng)前頁) Sub PageControl(iCount,pagecount,page) response.Write(style type=text/css/*謝亮分頁CSS*/div.pager{padding:10px
一款利用asp文件上傳組件把文件上傳到服務(wù)器之前進(jìn)行判斷文件大小否超過指定大小了,本實(shí)例講的是upload_5xsoft文件上傳組件哦,file.filesize>1000000就可以限制文件為多少k。
dim upload,file,formname,formpath,icount,filename,fileext
set upload=new upload_5xsoft '建立上傳對(duì)象
formpath="download/" '在目錄后加(/)
if right(formpath,1)<>"/" then formpath=formpath&"/"
for each formname in upload.file '列出所有上傳了的文件
set file=upload.file(formname) '生成一個(gè)文件對(duì)象
if file.filesize>1000000 then
message=1
else '如果 filesize <20000 說明有文件數(shù)據(jù)
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>大小超標(biāo)</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<script language=網(wǎng)頁特效>
function error_size()
{
alert("文件大小超過1000kb,請(qǐng)重新選擇。");
window.location="upload.asp";
}
</script>
</head>
<body bgcolor="#f2f2f2" leftmargin="0" topmargin="0" onload="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請(qǐng)選擇正確的文件類型!");
window.location="upload.asp";
}
</script>
</head>
<body bgcolor="#f2f2f2" leftmargin="0" topmargin="0" onload="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" onload="image_success()">
</body>
</html>
<% end if %>
<%
set file=nothing
set upload=nothing ''刪除此對(duì)象
%>
分享:網(wǎng)站制作ASP語言的特點(diǎn)與功能ASP(Active Server Page的縮寫) 意思是活動(dòng)服務(wù)器網(wǎng)頁。ASP是微軟公司開發(fā),用于代替CGI腳本程序的一種應(yīng)用. 它可以與數(shù)據(jù)庫和其它程序進(jìn)行交互,是一種簡單,方便的編程工具。ASP的網(wǎng)頁文件的格式為.asp,現(xiàn)常用于各種動(dòng)態(tài)網(wǎng)站中。 ASP是一種服務(wù)器端腳本編寫環(huán)境,可以用
- asp FSO 讀寫文件本文件實(shí)現(xiàn)代碼
- asp中isNull、isEmpty和空字符串的區(qū)別
- asp獲取用戶真實(shí)IP地址的方法
- asp連接sqlserver數(shù)據(jù)庫實(shí)現(xiàn)代碼
- asp中正則表達(dá)式過濾html代碼函數(shù)
- asp中g(shù)et post提交表單區(qū)別
- 網(wǎng)頁模板:ASP內(nèi)建對(duì)象Request
- xmlhttp的open方法使用詳解
- ASP的常用的自定義函數(shù)大全
- asp中用for循環(huán)的一個(gè)小技巧
- eWebEditor v3.8 列目錄
- ASP無組件分頁實(shí)現(xiàn)思路及代碼
- 相關(guān)鏈接:
- 教程說明:
ASP教程-asp限制上傳文件大小實(shí)例
。