文件上传

<% server.scripttimeout=3000 '指定更长时间，以防网速过慢造成服务器脚本超时！ dim fpath,EnableUpload dim upload,file,formName,formPath,iCount,filename,fileExt dim ranNum call upload_0() '===========无组件上传(upload_0)==================== sub upload_0() set upload=new UpFile_Class ''建立上传对象 upload.GetDate (10*1024*1024) '取得上传数据,是大数10M iCount=0 fpath=trim(upload.form("fpath")) if upload.err > 0 then select case upload.err case 1 response.write "
请先选择您要上传的文件! [重新上传]" case 2 response.write "
文件大小超过了限制 10M! [重新上传]" end select exit sub else formPath=fpath '存放上传文件的目录 if right(formPath,1)<>"/" then formPath=formPath&"/" '在目录后加(/) for each formName in upload.file ''列出所有上传了的文件 set file=upload.file(formName) ''生成一个文件对象 if file.filesize<100 then response.write "
请先选择您要上传的文件! [重新上传]" response.end end if fileExt=lcase(file.FileExt) if CheckFileExt(fileEXT)=false then response.write "
文件格式不正确! [重新上传]" response.end end if randomize ranNum=int(90000*rnd)+10000 filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据 file.SaveToFile Server.mappath(filename) '保存文件 if fpath="smallpic" then response.write "
" else response.write "
" end if iCount=iCount+1 end if set file=nothing next set upload=nothing Htmend iCount&"个文件上传结束!" end if end sub sub HtmEnd(Msg) response.write "
文件上传成功! [重新上传]" response.end end sub '判断文件类型是否合格 Private Function CheckFileExt (fileEXT) dim Forumupload,i if fpath="upload" then '上传swf Forumupload="swf|fla" else Forumupload="jpeg|bmp|png|gif|jpg" '允放上传的文件格式 end if 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 %>