asp限制上傳檔案大小執行個體

來源:互聯網
上載者:User

'一款利用asp檔案上傳組件把檔案上傳到伺服器之前進行判斷檔案大小否超過指定大小了,本執行個體講的是upload_5xsoft檔案上傳組件哦,file.filesize>1000000就可以限制檔案為多少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.filesize>1000000 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" 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請選擇正確的檔案類型!");
    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  ''刪除此對象
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.