UpFileSave.asp
上传用户:jisenq
上传日期:2014-06-29
资源大小:7216k
文件大小:6k
源码类别:

数据库编程

开发平台:

ASP/ASPX

  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
  2. <% Option Explicit %>
  3. <%Session.CodePage=936%> 
  4. <!--#include file="../../../FS_Inc/Const.asp" -->
  5. <!--#include file="../../../FS_Inc/Function.asp"-->
  6. <!--#include file="../../../FS_InterFace/MF_Function.asp" -->
  7. <!--#include file="../../../FS_InterFace/NS_Function.asp" -->
  8. <!--#include file="News_Upfile.asp" -->
  9. <!--#include file="../../../FS_Inc/WaterPrint_Function.asp" -->
  10. <%
  11. Dim Conn
  12. Dim TypeSql,RsTypeObj,LableSql,RsLableObj
  13. Dim FilePath,MaxFileSize,AllowFileExtStr,AutoReName,RsConfigObj,IsAddWaterMark
  14. Dim FormName,Path,UpFileObj
  15. Dim ReturnValue,str_MF_UpFile_Type,str_MF_UpFile_File_Size
  16. MF_Default_Conn
  17. if not MF_Check_Pop_TF("MF025") then Err_Show
  18. '=========================
  19. '读参数
  20. NS_GetMT_SysParm
  21. '==========================
  22. if str_MF_UpFile_File_Size <>"" then:MaxFileSize = clng(str_MF_UpFile_File_Size):Else:MaxFileSize =1024:End if
  23. if str_MF_UpFile_Type <>"" then:AllowFileExtStr = str_MF_UpFile_Type:Else:AllowFileExtStr = "jpg,gif,jpeg,png,bmp,txt,doc":End if
  24. Set UpFileObj = New UpFileClass
  25. UpFileObj.GetData
  26. FilePath=Server.MapPath(UpFileObj.Form("Path")) & ""
  27. AutoReName = UpFileObj.Form("AutoRename")
  28. IsAddWaterMark = UpFileObj.Form("chkAddWaterMark")
  29. If IsAddWaterMark <> "1" Then '生成是否要添加水印标记
  30. IsAddWaterMark = "9"
  31. End if
  32. ReturnValue = CheckUpFile(FilePath,MaxFileSize,AllowFileExtStr,AutoReName,IsAddWaterMark)
  33. if instr(ReturnValue,"Error")>0  then
  34. %>
  35. <script language="JavaScript">
  36. alert('<% = "以下文件上传失败,错误信息:n" & ReturnValue %>');
  37. dialogArguments.location.reload();
  38. close();
  39. </script>
  40. <%
  41. else
  42. if not isNull(ReturnValue) and instr(ReturnValue,"*")>0 then
  43. Session("upfiles")=split(ReturnValue,"*")(1)
  44. End if
  45. %>
  46. <script language="JavaScript">
  47. dialogArguments.location.reload();
  48. close();
  49. </script>
  50. <%
  51. end if
  52. Set UpFileObj=Nothing
  53. Function CheckUpFile(Path,FileSize,AllowExtStr,AutoReName,IsAddWaterMark)
  54. Dim ErrStr,NoUpFileTF,FsoObj,FileName,FileExtName,FileContent,SameFileExistTF
  55. NoUpFileTF = True
  56. ErrStr = ""
  57. Set FsoObj = Server.CreateObject(G_FS_FSO)
  58. For Each FormName in UpFileObj.File
  59. SameFileExistTF = False
  60. FileName = UpFileObj.File(FormName).FileName
  61. If NoIllegalStr(FileName)=False Then
  62. ErrStr=ErrStr&"文件:上传被禁止!n"
  63. End If
  64. FileExtName = UpFileObj.File(FormName).FileExt
  65. FileContent = UpFileObj.File(FormName).FileData
  66. '是否存在重名文件
  67. if UpFileObj.File(FormName).FileSize > 1 then
  68. NoUpFileTF = False
  69. ErrStr = ""
  70. if UpFileObj.File(FormName).FileSize > CLng(FileSize)*1024 then
  71. ErrStr = ErrStr & FileName & "文件:超过了限制,最大只能上传" & FileSize & "K的文件n"
  72. end if
  73. if AutoRename = "0" then
  74. If FsoObj.FileExists(Path & FileName) = True  then
  75. ErrStr = ErrStr & FileName & "文件:存在同名文件n"
  76. else
  77. SameFileExistTF = True
  78. end if
  79. else
  80. SameFileExistTF = True
  81. End If
  82. if CheckFileType(AllowExtStr,FileExtName) = False then
  83. ErrStr = ErrStr & FileName & "文件:不允许上传,上传文件类型有" + AllowExtStr + "n"
  84. end if
  85. if ErrStr = "" then
  86. if SameFileExistTF = True then
  87. CheckUpFile=CheckUpFile&"*"&SaveFile(Path,FormName,AutoReName,IsAddWaterMark)
  88. else
  89. CheckUpFile=CheckUpFile&"*"&SaveFile(Path,FormName,"",IsAddWaterMark)
  90. end if
  91. else
  92. CheckUpFile ="Error:"& CheckUpFile & ErrStr
  93. end if
  94. end if
  95. Next
  96. Set FsoObj = Nothing
  97. if NoUpFileTF = True then
  98. CheckUpFile = "没有上传文件"
  99. end if
  100. End Function
  101. Function CheckFileType(AllowExtStr,FileExtName)
  102. Dim i,AllowArray
  103. AllowArray = Split(AllowExtStr,",")
  104. FileExtName = LCase(FileExtName)
  105. CheckFileType = False
  106. For i = LBound(AllowArray) to UBound(AllowArray)
  107. if LCase(AllowArray(i)) = LCase(FileExtName) then
  108. CheckFileType = True
  109. end if
  110. Next
  111. if FileExtName="asp" or FileExtName="asa" or FileExtName="aspx" or  FileExtName="php" or  FileExtName="php3" or  FileExtName="php4"  or  FileExtName="php5"then
  112. CheckFileType = False
  113. end if
  114. End Function
  115. Function DealExtName(Byval UpFileExt)
  116. If IsEmpty(UpFileExt) Then Exit Function
  117. DealExtName = Lcase(UpFileExt)
  118. DealExtName = Replace(DealExtName,Chr(0),"")
  119. DealExtName = Replace(DealExtName,".","")
  120. DealExtName = Replace(DealExtName,"'","")
  121. DealExtName = Replace(DealExtName,"asp","")
  122. DealExtName = Replace(DealExtName,"asa","")
  123. DealExtName = Replace(DealExtName,"aspx","")
  124. DealExtName = Replace(DealExtName,"cer","")
  125. DealExtName = Replace(DealExtName,"cdx","")
  126. DealExtName = Replace(DealExtName,"htr","")
  127. DealExtName = Replace(DealExtName,"php","")
  128. End Function
  129. Function NoIllegalStr(Byval FileNameStr)
  130. Dim Str_Len,Str_Pos
  131. Str_Len=Len(FileNameStr)
  132. Str_Pos=InStr(FileNameStr,Chr(0))
  133. If Str_Pos=0 or Str_Pos=Str_Len then
  134.   NoIllegalStr=True
  135. Else
  136.   NoIllegalStr=False
  137. End If
  138. End function
  139. Function SaveFile(FilePath,FormNameItem,AutoNameType,IsAddWaterMark)
  140. Dim FileName,FileExtName,FileContent,FormName,RandomFigure
  141. Randomize 
  142. RandomFigure = CStr(Int((99999 * Rnd) + 1))
  143. FileName = UpFileObj.File(FormNameItem).FileName
  144. FileExtName = UpFileObj.File(FormNameItem).FileExt
  145. FileExtName=DealExtName(FileExtName)
  146. FileContent = UpFileObj.File(FormNameItem).FileData
  147. If AutoNameType = "1" Then
  148. FileName = FilePath & "副件" & FileName
  149. elseif AutoNameType = "2" Then
  150. FileName = FilePath & "1" & FileName 
  151. elseif AutoNameType = "3" Then
  152. FileName = FilePath & Year(Now())&Right("0"&Month(Now()),2)&Right("0"&Day(Now()),2)&Right("0"&Hour(Now()),2)&Right("0"&Minute(Now()),2)&Right("0"&Second(Now()),2)&RandomFigure&"."&FileExtName
  153. Else
  154. FileName = FilePath&FileName
  155. End If
  156. UpFileObj.File(FormNameItem).SaveToFile FileName
  157. If IsAddWaterMark = "1" Then   '在保存好的图片上添加水印
  158. AddWaterMark FileName
  159. End if
  160. SaveFile=mid(FileName,instrrev(FileName,"")+1,len(FileName))
  161. End Function
  162. Set Conn = Nothing
  163. %>