ASP limit upload File size instance

Source: Internet
Author: User
Tags file upload rar save file zip

' An ASP file upload component to the file uploaded to the server before to determine whether the file size exceeds the specified size, this example is Upload_5xsoft file upload components Oh, file.filesize>1000000 can limit the number of K file.


Dim upload,file,formname,formpath,icount,filename,fileext
Set upload=new upload_5xsoft ' Build upload Object
Formpath= "download/" ' in the Catalogue plus (/)
If Right (formpath,1) <> "/" Then formpath=formpath& "/"
For every formname in Upload.file ' lists all uploaded files
Set File=upload.file (formname) ' generates a File object
If file.filesize>1000000 Then
Message=1
Else ' If FileSize <20000 indicates that there are file data
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) ' Save file '
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%>
<title> size exceeded </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language= Web page Special effects >
function Error_size ()
{
Alert ("File size is over 1000KB, please select again.") ");
Window.location= "Upload.asp";
}
</script>
<body bgcolor= "#f2f2f2" leftmargin= "0" topmargin= "0" onload= "error_size ()" >
</body>
<% ElseIf message=2 then%>
<title> Type mismatch </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language=javascript>
function Error_type ()
{
Alert ("Only upload ZIP/RAR/EXE/MXP file n Please select the correct file type!") ");
Window.location= "Upload.asp";
}
</script>
<body bgcolor= "#f2f2f2" leftmargin= "0" topmargin= "0" onload= "Error_type ()" >
</body>
<% ElseIf message=3 then%>
<title> Upload Success </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language=javascript>
function image_success ()
{
Alert ("File Upload success!") ");
Parent.form1.url1.value= "<%=uploadchar%>"
Parent.form1.size.value= "<%=size%>k"
Window.location= "Upload.asp";
}
</script>
<body bgcolor= "#f2f2f2" leftmargin= "0" topmargin= "0" onload= "image_success ()" >
</body>
<% End If%>
<%
Set file=nothing
Set Upload=nothing ' Deletes this object
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.