class_upload.asp
上传用户:li2971742
上传日期:2021-11-18
资源大小:39096k
文件大小:6k
源码类别:

OA系统

开发平台:

C#

  1. <!--
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2006 Frederico Caldeira Knabben
  4.  * 
  5.  * Licensed under the terms of the GNU Lesser General Public License:
  6.  *  http://www.opensource.org/licenses/lgpl-license.php
  7.  * 
  8.  * For further information visit:
  9.  *  http://www.fckeditor.net/
  10.  * 
  11.  * "Support Open Source software. What about a donation today?"
  12.  * 
  13.  * File Name: class_upload.asp
  14.  *  These are the classes used to handle ASP upload without using third
  15.  *  part components (OCX/DLL).
  16.  * 
  17.  * File Authors:
  18.  *  NetRube (netrube@126.com)
  19. -->
  20. <%
  21. '**********************************************
  22. ' File: NetRube_Upload.asp
  23. ' Version: NetRube Upload Class Version 2.1 Build 20050228
  24. ' Author: NetRube
  25. ' Email: NetRube@126.com
  26. ' Date: 02/28/2005
  27. ' Comments: The code for the Upload.
  28. ' This can free usage, but please
  29. ' not to delete this copyright information.
  30. ' If you have a modification version,
  31. ' Please send out a duplicate to me.
  32. '**********************************************
  33. ' 文件名: NetRube_Upload.asp
  34. ' 版本: NetRube Upload Class Version 2.1 Build 20050228
  35. ' 作者: NetRube(网络乡巴佬)
  36. ' 电子邮件: NetRube@126.com
  37. ' 日期: 2005年02月28日
  38. ' 声明: 文件上传类
  39. ' 本上传类可以自由使用,但请保留此版权声明信息
  40. ' 如果您对本上传类进行修改增强,
  41. ' 请发送一份给俺。
  42. '**********************************************
  43. Class NetRube_Upload
  44. Public File, Form
  45. Private oSourceData
  46. Private nMaxSize, nErr, sAllowed, sDenied
  47. Private Sub Class_Initialize
  48. nErr = 0
  49. nMaxSize = 1048576
  50. Set File = Server.CreateObject("Scripting.Dictionary")
  51. File.CompareMode = 1
  52. Set Form = Server.CreateObject("Scripting.Dictionary")
  53. Form.CompareMode = 1
  54. Set oSourceData = Server.CreateObject("ADODB.Stream")
  55. oSourceData.Type = 1
  56. oSourceData.Mode = 3
  57. oSourceData.Open
  58. End Sub
  59. Private Sub Class_Terminate
  60. Form.RemoveAll
  61. Set Form = Nothing
  62. File.RemoveAll
  63. Set File = Nothing
  64. oSourceData.Close
  65. Set oSourceData = Nothing
  66. End Sub
  67. Public Property Get Version
  68. Version = "NetRube Upload Class Version 1.0 Build 20041218"
  69. End Property
  70. Public Property Get ErrNum
  71. ErrNum = nErr
  72. End Property
  73. Public Property Let MaxSize(nSize)
  74. nMaxSize = nSize
  75. End Property
  76. Public Property Let Allowed(sExt)
  77. sAllowed = sExt
  78. End Property
  79. Public Property Let Denied(sExt)
  80. sDenied = sExt
  81. End Property
  82. Public Sub GetData
  83. Dim aCType
  84. aCType = Split(Request.ServerVariables("HTTP_CONTENT_TYPE"), ";")
  85. If aCType(0) <> "multipart/form-data" Then
  86. nErr = 1
  87. Exit Sub
  88. End If
  89. Dim nTotalSize
  90. nTotalSize = Request.TotalBytes
  91. If nTotalSize < 1 Then
  92. nErr = 2
  93. Exit Sub
  94. End If
  95. If nMaxSize > 0 And nTotalSize > nMaxSize Then
  96. nErr = 3
  97. Exit Sub
  98. End If
  99. oSourceData.Write Request.BinaryRead(nTotalSize)
  100. oSourceData.Position = 0
  101. Dim oTotalData, oFormStream, sFormHeader, sFormName, bCrLf, nBoundLen, nFormStart, nFormEnd, nPosStart, nPosEnd, sBoundary
  102. oTotalData = oSourceData.Read
  103. bCrLf = ChrB(13) & ChrB(10)
  104. sBoundary = MidB(oTotalData, 1, InStrB(1, oTotalData, bCrLf) - 1)
  105. nBoundLen = LenB(sBoundary) + 2
  106. nFormStart = nBoundLen
  107. Set oFormStream = Server.CreateObject("ADODB.Stream")
  108. Do While (nFormStart + 2) < nTotalSize
  109. nFormEnd = InStrB(nFormStart, oTotalData, bCrLf & bCrLf) + 3
  110. With oFormStream
  111. .Type = 1
  112. .Mode = 3
  113. .Open
  114. oSourceData.Position = nFormStart
  115. oSourceData.CopyTo oFormStream, nFormEnd - nFormStart
  116. .Position = 0
  117. .Type = 2
  118. .CharSet = "UTF-8"
  119. sFormHeader = .ReadText
  120. .Close
  121. End With
  122. nFormStart = InStrB(nFormEnd, oTotalData, sBoundary) - 1
  123. nPosStart = InStr(22, sFormHeader, " name=", 1) + 7
  124. nPosEnd = InStr(nPosStart, sFormHeader, """")
  125. sFormName = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
  126. If InStr(45, sFormHeader, " filename=", 1) > 0 Then
  127. Set File(sFormName) = New NetRube_FileInfo
  128. File(sFormName).FormName = sFormName
  129. File(sFormName).Start = nFormEnd
  130. File(sFormName).Size = nFormStart - nFormEnd - 2
  131. nPosStart = InStr(nPosEnd, sFormHeader, " filename=", 1) + 11
  132. nPosEnd = InStr(nPosStart, sFormHeader, """")
  133. File(sFormName).ClientPath = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
  134. File(sFormName).Name = Mid(File(sFormName).ClientPath, InStrRev(File(sFormName).ClientPath, "") + 1)
  135. File(sFormName).Ext = LCase(Mid(File(sFormName).Name, InStrRev(File(sFormName).Name, ".") + 1))
  136. nPosStart = InStr(nPosEnd, sFormHeader, "Content-Type: ", 1) + 14
  137. nPosEnd = InStr(nPosStart, sFormHeader, vbCr)
  138. File(sFormName).MIME = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
  139. Else
  140. With oFormStream
  141. .Type = 1
  142. .Mode = 3
  143. .Open
  144. oSourceData.Position = nPosEnd
  145. oSourceData.CopyTo oFormStream, nFormStart - nFormEnd - 2
  146. .Position = 0
  147. .Type = 2
  148. .CharSet = "UTF-8"
  149. Form(sFormName) = .ReadText
  150. .Close
  151. End With
  152. End If
  153. nFormStart = nFormStart + nBoundLen
  154. Loop
  155. oTotalData = ""
  156. Set oFormStream = Nothing
  157. End Sub
  158. Public Sub SaveAs(sItem, sFileName)
  159. If File(sItem).Size < 1 Then
  160. nErr = 2
  161. Exit Sub
  162. End If
  163. If Not IsAllowed(File(sItem).Ext) Then
  164. nErr = 4
  165. Exit Sub
  166. End If
  167. Dim oFileStream
  168. Set oFileStream = Server.CreateObject("ADODB.Stream")
  169. With oFileStream
  170. .Type = 1
  171. .Mode = 3
  172. .Open
  173. oSourceData.Position = File(sItem).Start
  174. oSourceData.CopyTo oFileStream, File(sItem).Size
  175. .Position = 0
  176. .SaveToFile sFileName, 2
  177. .Close
  178. End With
  179. Set oFileStream = Nothing
  180. End Sub
  181. Private Function IsAllowed(sExt)
  182. Dim oRE
  183. Set oRE = New RegExp
  184. oRE.IgnoreCase = True
  185. oRE.Global = True
  186. If sDenied = "" Then
  187. oRE.Pattern = sAllowed
  188. IsAllowed = (sAllowed = "") Or oRE.Test(sExt)
  189. Else
  190. oRE.Pattern = sDenied
  191. IsAllowed = Not oRE.Test(sExt)
  192. End If
  193. Set oRE = Nothing
  194. End Function
  195. End Class
  196. Class NetRube_FileInfo
  197. Dim FormName, ClientPath, Path, Name, Ext, Content, Size, MIME, Start
  198. End Class
  199. %>