UpFileSave.asp
Upload User: jisenq
Upload Date: 2014-06-29
Package Size: 7216k
Code Size: 6k
Category:

ADO-ODBC

Development Platform:

ASP/ASPX

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