熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp限制上傳文件大小實例

2022-06-13   來源: .NET編程 

  一款利用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  刪除此對象
%>


From:http://tw.wingwit.com/Article/program/net/201311/14285.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.