<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Server.scriptTimeout=300 %> Uploading
<% dim Upload,File,FormName,SaveToPath,FileName,FileExt dim RanNum call UpFile() '===========无组件上传(upload_0)==================== sub UpFile() set Upload=new UpFile_Class '建立上传对象 Upload.GetData (1024*1024*15) '取得上传数据,此处即为15M if Upload.err > 0 then select case Upload.err case 1 Response.Write "Please select your file to upload,Return !" case 2 Response.Write "File size exceeds the limit of 15M,Return !" end select exit sub else SaveToPath=Upload.form("SaveToPath") '文件保存目录,此目录必须为程序可读写 if SaveToPath="" then SaveToPath="../" end if '在目录后加(/) if right(SaveToPath,1)<>"/" then SaveToPath=SaveToPath&"/" end if for each FormName in Upload.file '列出所有上传了的文件 set file=Upload.file(FormName) '生成一个文件对象 if file.Filesize<100 then response.write "Please select your file to upload,Return !" response.end end if FileExt=lcase(File.FileExt) if CheckFileExt(FileEXT)=false then response.write "The file format is not allowed to upload,Return !" response.end end if randomize timer RanNum=int(9000*rnd)+1000 Filename=SaveToPath&year(now)&"."&month(now)&"."&day(now)&"_"&hour(now)&"."&minute(now)&"."&Second(now)&"_"&RanNum&"."&fileExt if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据 Result=file.SaveToFile(Server.mappath(FileName)) '保存文件 if Result="ok" then response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "" response.write "
Succeed:"&File.FilePath&file.FileName&"
Hold:
Size:
" else response.write File.FilePath&file.FileName&"Failed to upload !"&Result&"
" end if end if set file=nothing next set Upload=nothing end if end sub '判断文件类型是否合格 Private Function CheckFileExt (FileEXT) dim ForumUpload ForumUpload="exe,gif,jpg,jpeg,rar,zip,doc" ForumUpload=split(ForumUpload,",") for i=0 to ubound(ForumUpload) if lcase(FileEXT)=lcase(trim(ForumUpload(i))) then CheckFileExt=true exit Function else CheckFileExt=false end if next End Function Private Function GainFileSize (SizeByte) if SizeByte < 1024*1024 then GainFileSize=round(SizeByte/1024,2) & " KB" else GainFileSize=round(SizeByte/1024/1024,2) & " MB" end if End Function %>