' 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
%>