class_upload.asp
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:6k
源码类别:

Jsp/Servlet

开发平台:

Java

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