www.gusucode.com > cso中国seo优化html整站源码程序 > manage/upfile.asp
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <!--#include file="upload.inc"--> <% Function CreateFolder(folderpath) Dim fso,f,fldr fldr = server.mappath(folderpath) Set fso = CreateObject("Scripting.FileSystemObject") if fso.FolderExists(fldr) = false then Set f = fso.CreateFolder(fldr) else exit function end if set fso = nothing End Function Set Upload = New UpFile_Class ''建立上传对象 Upload.InceptFileType = "gif,jpg,bmp,jpeg,png,swf,doc,pdf,rar" '上传类型限制 Upload.MaxSize = 10240000 '限制大小 Upload.GetDate() '取得上传数据 If Upload.Err > 0 Then Select Case Upload.Err Case 1 : Response.Write "请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]" Case 2 : Response.Write "图片大小超过了限制 10m [ <a href=# onclick=history.go(-1)>重新上传</a> ]" Case 3 : Response.Write "所上传类型不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]" End Select Else FormPath=Upload.Form("filepath") ystr = right(year(now),2) mstr = Month(now) if mstr < 10 then mstr = "0" & mstr formpath = formpath & ystr & mstr & "/" call CreateFolder(formpath) For Each FormName in Upload.file ''列出所有上传了的文件 Set File = Upload.File(FormName) ''生成一个文件对象 If File.Filesize<10 Then Response.Write "请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]" End If FileExt = FixName(File.FileExt) If Not CheckFileExt(FileExt) Then Response.Write "文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]" End If FileName=FormPath&UserFaceName(FileExt) If File.FileSize>0 Then ''如果 FileSize > 0 说明有文件数据 File.SaveToFile Server.mappath(FileName) ''保存文件 response.write "<script>window.opener.document."&upload.form("FormName")&"."&upload.form("EditName")&".value='"&FileName&"'</script>" Response.Write "<script language=""javascript"">window.alert(""文件上传成功!请不要修改生成的链接地址!"");window.close();</script>" End If Set File=Nothing Next End If Set Upload=Nothing '判断文件类型是否合格 Private Function CheckFileExt(FileExt) Dim ForumUpload,i ForumUpload="gif,jpg,bmp,jpeg,png,swf,doc,pdf,rar" ForumUpload=Split(ForumUpload,",") CheckFileExt=False For i=0 to UBound(ForumUpload) If LCase(FileExt)=Lcase(Trim(ForumUpload(i))) Then CheckFileExt=True Exit Function End If Next End Function '格式后缀 Function FixName(UpFileExt) If IsEmpty(UpFileExt) Then Exit Function FixName = Lcase(UpFileExt) FixName = Replace(FixName,Chr(0),"") FixName = Replace(FixName,".","") FixName = Replace(FixName,"asp","") FixName = Replace(FixName,"asa","") FixName = Replace(FixName,"aspx","") FixName = Replace(FixName,"cer","") FixName = Replace(FixName,"cdx","") FixName = Replace(FixName,"htr","") End Function '文件名明名 Private Function UserFaceName(FileExt) dstr = Day(now) if dstr < 10 then dstr = "0" & dstr hstr = Hour(now) if hstr < 10 then hstr = "0" & hstr mmstr = Minute(now) if mmstr < 10 then mmstr = "0" & mmstr sstr = Second(now) if sstr < 10 then sstr = "0" & sstr UserFaceName = dstr & hstr & mmstr & sstr & "." & FileExt End Function %>