<% dim lid lid=TRim(Request("lid")) dim picsy,picsize,formatpic set rs=server.CreateObject("adodb.recordset") sql="select formatpic,picsize,picsy from twapp" rs.open sql,conn,1,1 formatpic=rs("formatpic") picsize=rs("picsize") picsy=rs("picsy") rs.close set rs=nothing Server.ScriptTimeOut=9999999 AllowFileType= ""&formatpic&"" '允许上传的图片类型,用“,”隔开 AllowFileSize=""&picsize&"" '最大上传图片,以KB为单位 Const G_FS_FSO = "Scripting.FileSystemObject" '--------------------------------------------------------------------------- Dim Create_DateCatalog Create_DateCatalog = False '--------------------------------------------------------------------------- Dim AutoReName,UpFileObj,FileObject,FormName,FileName,FileExtStr,strFileName Dim Fso,SavePath,AutoSavePath,AppearErr,ClueOn_Msg,StrJs,iCount Dim SameFileTF,No_UpFileTF,RealityPath '--------------------------------------------------------------------------- SavePath = "/pic/" If Right(SavePath,1) <> "/" Then SavePath = SavePath & "/" End If Set UpFileObj = New UpFile_Class UpFileObj.GetData(102400000000000000) AutoReName = "2" 'Trim(UpFileObj.Form("AutoRename")) ClueOn_Msg = "" No_UpFileTF = True AppearErr = False If IsObjInstalled(G_FS_FSO) = True Then dim name,title,laiy,rs1,sql1,rs2,sql2,idc,leibie name=UpFileObj.Form("name") laiy=UpFileObj.Form("laiy") if name="" or laiy="" then ClueOn_Msg = "各项都要填写!" AppearErr = True UpFileError End If set rs1=server.CreateObject("adodb.recordset") sql1="select * from wjfile" rs1.open sql1,conn,1,3 Rs1.addnew Rs1("name")=name Rs1("times")=now() Rs1("lid")=lid Rs1("laiy")=laiy Rs1("typeID")=1 Rs1.Update Rs1.close Set Rs1=nothing set rs2=server.CreateObject("adodb.recordset") sql2="select top 1 id from wjfile order by id desc" rs2.open sql2,conn,1,1 idc=rs2("id") Rs2.close Set Rs2=nothing '--------------------------------------------------------------------------- Set Fso = Server.CreateObject(G_FS_FSO) iCount=0 '--------------------------------------------------------------------------- For Each FormName in UpFileObj.File Set FileObject = UpFileObj.File(FormName) SameFileTF = False FileName = FileObject.FileName If NoIiiegalStr(FileName) = False Then ClueOn_Msg = "上传被禁止!" AppearErr = True UpFileError End If FileExtStr = FileObject.FileExt If FileObject.FileSize > 1 Then '---------------------------------------------------------------------------- If Fso.FolderExists(Server.MapPath(SavePath)) = True Then If Create_DateCatalog = True Then AutoSavePath = Year(Now()) & Right("0" & Month(Now()),2) & "/" SavePath = SavePath & AutoSavePath If Not Fso.FolderExists(Server.MapPath(SavePath)) Then Fso.CreateFolder Server.MapPath(SavePath) End If End If Else ClueOn_Msg = "目录不存在,无法上传图片!" AppearErr = True UpFileError End If RealityPath = Server.MapPath(SavePath) & "\" '----------------------------------------------------------------------------- No_UpFileTF = False If FileObject.FileSize > Clng(AllowFileSize)*1024 Then ClueOn_Msg = "图片"&FileName&"超过了限制!
最大只能上传" & AllowFileSize & "K的图片" AppearErr = True UpFileError End If IF AutoRename = "1" Then If Fso.FileExists(RealityPath & FileName) = True Then ClueOn_Msg = "图片已存在!" AppearErr = True Else SameFileTF = False End If Else SameFileTF = True End If FileName = Replace(FileName,"jpeg","jpg") If CheckFileType(AllowFileType,FileName) = False Then ClueOn_Msg = "此图片不允许上传!
"&vbCrLf&"允许上传图片类型有"& AllowFileType AppearErr = True UpFileError End If If AppearErr <> True Then If SameFileTF = True Then strFileName = DateStr & rndStr(5) & "." & DealExtName(FileExtStr) Else strFileName = ReplaceExt(FileName,"shit") End If FileObject.SaveToFile Server.MapPath(SavePath & strFileName) ClueOn_Msg = "图片已经成功上传!
" dim SaveFilePath SaveFilePath=Replace(SavePath&strFileName,"\","/") if picsy=1 then IF InStrRev(SaveFilePath,".") > 0 THEN dim ggss ggss= mid(SaveFilePath,InStrRev(SaveFilePath,".")+1) end if 'if ggss="jpg" or ggss="jpeg" or ggss="bmp" or ggss="png" then 'Dim Jpeg,Path 'Set Jpeg = Server.CreateObject("Persits.Jpeg") 'Path = Server.MapPath(SavePath & strFileName) 'Jpeg.Open Path 'Jpeg.Canvas.Font.Color = &HFFFFFF '颜色 'Jpeg.Canvas.Font.Family = "宋体" '字体 'Jpeg.Canvas.Font.Size = 15 '字体大小 'Jpeg.Canvas.Font.Bold = true '是否为粗体 'Jpeg.Canvas.Font.ShadowColor = &HFFFFFF '字影颜色 'Jpeg.Canvas.Print 5,3,request.ServerVariables("Server_NAME") 'Jpeg.Save Server.MapPath(SavePath & strFileName) 'Set Jpeg = Nothing 'end if end if iCount=iCount+1 Dim SaveFileType,SaveFileName,SaveFileSize,FileDescriptions SaveFileSize=Formatnumber(FileObject.FileSize/1024,2,-1,-1,0) FileDescriptions=UpFileObj.Form("Descriptions") ClueOn_Msg=ClueOn_Msg&vbCrLf&"请返回
"&vbCrLf IF InStrRev(SaveFilePath,".") > 0 THEN ggss = mid(SaveFilePath,InStrRev(SaveFilePath,".")+1) end if set rs1=server.CreateObject("adodb.recordset") sql1="select * from uppic" rs1.open sql1,conn,1,3 Rs1.addnew Rs1("picurl")=SaveFilePath Rs1("YD_size")=SaveFileSize Rs1("format")=ggss Rs1("lid")=idc Rs1.Update Rs1.close Set Rs1=nothing End If Else ClueOn_Msg = "请选择你要上传的文件!" UpFileError End If Next Set FileObject = Nothing Set Fso = Nothing Else ClueOn_Msg = "上传功能需要FSO组件支持,请检查该组件是否安装正确!" UpFileError End If UpFileSuccess Set UpFileObj = Nothing '//验证上传图片的合法性 Function CheckFileType(AllowFileType,FileExtStr) Dim i,AllowArray,AllowCount,FileExtName AllowArray=Split(AllowFileType,",") AllowCount=Ubound(AllowArray) FileExtName=Right(FileName,3) IF AllowCount>0 Then For i = LBound(AllowArray) to UBound(AllowArray) IF LCase(AllowArray(i))=LCase(FileExtName) Then CheckFileType=True Exit For End IF Next End IF IF FileExtName="asp" or FileExtName="asa" or FileExtName="aspx" or FileExtName="cer" or FileExtName="php" or FileExtName="cdx" or FileExtName="htr" or FileExtName="exe" Then CheckFileType = False End If End Function '//检查图片名格式 Function NoIiiegalStr(Byval FileNameStr) Dim Str_Len,Str_Pos Str_Len = Len(FileNameStr) Str_Pos = InStr(FileNameStr,Chr(0)) If Str_Pos = 0 or Str_Pos = Str_Len then NoIiiegalStr = True Else NoIiiegalStr = False End If End function '//替换掉禁止的图片类型 Function DealExtName(Byval UpFileExt) If IsEmpty(UpFileExt) Then Exit Function DealExtName = Lcase(UpFileExt) DealExtName = Replace(DealExtName,Chr(0),"") DealExtName = Replace(DealExtName," ","") DealExtName = Replace(DealExtName," ","") DealExtName = Replace(DealExtName,Chr(255),"") DealExtName = Replace(DealExtName,".","") DealExtName = Replace(DealExtName,"'","") DealExtName = Replace(DealExtName,"asp","") DealExtName = Replace(DealExtName,"asa","") DealExtName = Replace(DealExtName,"aspx","") DealExtName = Replace(DealExtName,"cer","") DealExtName = Replace(DealExtName,"cdx","") DealExtName = Replace(DealExtName,"htr","") DealExtName = Replace(DealExtName,"php","") DealExtName = Replace(DealExtName,"exe","") End Function '//如果不开启自动命名,则执行替换 '//替换非法图片为自定义字符串 Function ReplaceExt(Byval ExtStr,Byval RepExt) If IsEmpty(ExtStr) or IsEmpty(RepExt) Then Exit Function ReplaceExt = Lcase(ExtStr) ReplaceExt = Replace(ReplaceExt,Chr(0),"") ReplaceExt = Replace(ReplaceExt," ","") ReplaceExt = Replace(ReplaceExt," ","") ReplaceExt = Replace(ReplaceExt,Chr(255),"") ReplaceExt = Replace(ReplaceExt,"'","") ReplaceExt = Replace(Replace(ReplaceExt,"asp",RepExt),".asp","sp" & RepExt) ReplaceExt = Replace(Replace(ReplaceExt,"asa",RepExt),".asa","sa" & RepExt) ReplaceExt = Replace(Replace(ReplaceExt,"aspx",RepExt),".aspx","spx" & RepExt) ReplaceExt = Replace(Replace(ReplaceExt,"cer",RepExt),".cer","er" & RepExt) ReplaceExt = Replace(Replace(ReplaceExt,"cdx",RepExt),".cdx","dx" & RepExt) ReplaceExt = Replace(Replace(ReplaceExt,"htr",RepExt),".htr","tr" & RepExt) ReplaceExt = Replace(Replace(ReplaceExt,"php",RepExt),".php","hp" & RepExt) ReplaceExt = Replace(Replace(ReplaceExt,"exe",RepExt),".exe","xe" & RepExt) End Function '//产生一个日期字符串 Function DateStr() Dim iYear,iMonth,iDay,iHour,iMinute,iScond iYear = Year(Now) iMonth = Month(Now) iDay = Day(Now) iHour = CStr(Hour(Now())) If Len(iHour) = 1 Then iHour = "0" & iHour End If iMinute = CStr(Minute(Now())) If Len(iMinute) = 1 Then iMinute = "0" & iMinute End If iScond = CStr(Second(Now())) If Len(iScond) = 1 Then iScond = "0" & iScond End If DateStr = iYear & iMonth & iDay & iHour & iMinute & iScond End Function '//生成指定位数的字符 Function rndStr(strLong) Dim tempStr Randomize Do while Len(rndStr) < strLong tempStr = CStr(Chr((57-48)*rnd+48)) rndStr = rndStr & tempStr Loop rndStr = rndStr End Function '//检查组件是否安装 Function IsObjInstalled(ByVal strClassString) Dim xTestObj,ClsString On Error Resume Next IsObjInstalled = False ClsString = strClassString Err = 0 Set xTestObj = Server.CreateObject(ClsString) If Err = 0 Then IsObjInstalled = True If Err = -2147352567 Then IsObjInstalled = True Set xTestObj = Nothing Err = 0 Exit Function End Function %> <%Sub UpFileError()%> WAP2.0图片上传 <%=ClueOn_Msg%>
[图片列表]
[图片类别]
[后台管理] <%Response.End%><%End Sub%> <%Sub UpFileSuccess()%> WAP2.0图片上传 <%=ClueOn_Msg%>
[图片列表]
[图片类别]
[后台管理] <%Response.End%><%End Sub%>