2
' FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
' Copyright (C) 2003-2008 Frederico Caldeira Knabben
7
' Licensed under the terms of any of the following licenses at your
10
' - GNU General Public License Version 2 or later (the "GPL")
11
' http://www.gnu.org/licenses/gpl.html
13
' - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14
' http://www.gnu.org/licenses/lgpl.html
16
' - Mozilla Public License Version 1.1 or later (the "MPL")
17
' http://www.mozilla.org/MPL/MPL-1.1.html
21
' These are the classes used to handle ASP upload without using third
22
' part components (OCX/DLL).
25
'**********************************************
26
' File: NetRube_Upload.asp
27
' Version: NetRube Upload Class Version 2.3 Build 20070528
29
' Email: NetRube@126.com
31
' Comments: The code for the Upload.
32
' This can free usage, but please
33
' not to delete this copyright information.
34
' If you have a modification version,
35
' Please send out a duplicate to me.
36
'**********************************************
37
' 文件名: NetRube_Upload.asp
38
' 版本: NetRube Upload Class Version 2.3 Build 20070528
40
' 电子邮件: NetRube@126.com
43
' 本上传类可以自由使用,但请保留此版权声明信息
46
'**********************************************
52
Private nMaxSize, nErr, sAllowed, sDenied, sHtmlExtensions
54
Private Sub Class_Initialize
58
Set File = Server.CreateObject("Scripting.Dictionary")
60
Set Form = Server.CreateObject("Scripting.Dictionary")
63
Set oSourceData = Server.CreateObject("ADODB.Stream")
69
Private Sub Class_Terminate
76
Set oSourceData = Nothing
79
Public Property Get Version
80
Version = "NetRube Upload Class Version 2.3 Build 20070528"
83
Public Property Get ErrNum
87
Public Property Let MaxSize(nSize)
91
Public Property Let Allowed(sExt)
95
Public Property Let Denied(sExt)
99
Public Property Let HtmlExtensions(sExt)
100
sHtmlExtensions = sExt
105
aCType = Split(Request.ServerVariables("HTTP_CONTENT_TYPE"), ";")
106
if ( uBound(aCType) < 0 ) then
110
If aCType(0) <> "multipart/form-data" Then
116
nTotalSize = Request.TotalBytes
117
If nTotalSize < 1 Then
121
If nMaxSize > 0 And nTotalSize > nMaxSize Then
126
'Thankful long(yrl031715@163.com)
127
'Fix upload large file.
128
'**********************************************
130
' 联系邮件: yrl031715@163.com
132
' 修正说明:由于iis6的Content-Length 头信息中包含的请求长度超过了 AspMaxRequestEntityAllowed 的值(默认200K), IIS 将返回一个 403 错误信息.
133
' 直接导致在iis6下调试FCKeditor上传功能时,一旦文件超过200K,上传文件时文件管理器失去响应,受此影响,文件的快速上传功能也存在在缺陷。
134
' 在参考 宝玉 的 Asp无组件上传带进度条 演示程序后作出如下修改,以修正在iis6下的错误。
136
Dim nTotalBytes, nPartBytes, ReadBytes
138
nTotalBytes = Request.TotalBytes
140
Do While ReadBytes < nTotalBytes
142
nPartBytes = 64 * 1024 '分成每块64k
143
If nPartBytes + ReadBytes > nTotalBytes Then
144
nPartBytes = nTotalBytes - ReadBytes
146
oSourceData.Write Request.BinaryRead(nPartBytes)
147
ReadBytes = ReadBytes + nPartBytes
149
'**********************************************
150
oSourceData.Position = 0
152
Dim oTotalData, oFormStream, sFormHeader, sFormName, bCrLf, nBoundLen, nFormStart, nFormEnd, nPosStart, nPosEnd, sBoundary
154
oTotalData = oSourceData.Read
155
bCrLf = ChrB(13) & ChrB(10)
156
sBoundary = MidB(oTotalData, 1, InStrB(1, oTotalData, bCrLf) - 1)
157
nBoundLen = LenB(sBoundary) + 2
158
nFormStart = nBoundLen
160
Set oFormStream = Server.CreateObject("ADODB.Stream")
162
Do While (nFormStart + 2) < nTotalSize
163
nFormEnd = InStrB(nFormStart, oTotalData, bCrLf & bCrLf) + 3
169
oSourceData.Position = nFormStart
170
oSourceData.CopyTo oFormStream, nFormEnd - nFormStart
174
sFormHeader = .ReadText
178
nFormStart = InStrB(nFormEnd, oTotalData, sBoundary) - 1
179
nPosStart = InStr(22, sFormHeader, " name=", 1) + 7
180
nPosEnd = InStr(nPosStart, sFormHeader, """")
181
sFormName = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
183
If InStr(45, sFormHeader, " filename=", 1) > 0 Then
184
Set File(sFormName) = New NetRube_FileInfo
185
File(sFormName).FormName = sFormName
186
File(sFormName).Start = nFormEnd
187
File(sFormName).Size = nFormStart - nFormEnd - 2
188
nPosStart = InStr(nPosEnd, sFormHeader, " filename=", 1) + 11
189
nPosEnd = InStr(nPosStart, sFormHeader, """")
190
File(sFormName).ClientPath = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
191
File(sFormName).Name = Mid(File(sFormName).ClientPath, InStrRev(File(sFormName).ClientPath, "\") + 1)
192
File(sFormName).Ext = LCase(Mid(File(sFormName).Name, InStrRev(File(sFormName).Name, ".") + 1))
193
nPosStart = InStr(nPosEnd, sFormHeader, "Content-Type: ", 1) + 14
194
nPosEnd = InStr(nPosStart, sFormHeader, vbCr)
195
File(sFormName).MIME = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)
201
oSourceData.Position = nFormEnd
202
oSourceData.CopyTo oFormStream, nFormStart - nFormEnd - 2
206
Form(sFormName) = .ReadText
211
nFormStart = nFormStart + nBoundLen
215
Set oFormStream = Nothing
218
Public Sub SaveAs(sItem, sFileName)
219
If File(sItem).Size < 1 Then
224
If Not IsAllowed(File(sItem).Ext) Then
229
If InStr( LCase( sFileName ), "::$data" ) > 0 Then
234
Dim sFileExt, iFileSize
235
sFileExt = File(sItem).Ext
236
iFileSize = File(sItem).Size
239
If Not IsHtmlExtension( sFileExt ) Then
240
' Calculate the size of data to load (max 1Kb).
244
If iXSSSize > 1024 Then
250
oSourceData.Position = File(sItem).Start
251
sData = oSourceData.Read( iXSSSize ) ' Byte Array
252
sData = ByteArray2Text( sData ) ' String
255
If SniffHtml( sData ) Then
262
Set oFileStream = Server.CreateObject("ADODB.Stream")
267
oSourceData.Position = File(sItem).Start
268
oSourceData.CopyTo oFileStream, File(sItem).Size
270
.SaveToFile sFileName, 2
273
Set oFileStream = Nothing
276
Private Function IsAllowed(sExt)
279
oRE.IgnoreCase = True
283
oRE.Pattern = sAllowed
284
IsAllowed = (sAllowed = "") Or oRE.Test(sExt)
286
oRE.Pattern = sDenied
287
IsAllowed = Not oRE.Test(sExt)
293
Private Function IsHtmlExtension( sExt )
294
If sHtmlExtensions = "" Then
300
oRE.IgnoreCase = True
302
oRE.Pattern = sHtmlExtensions
304
IsHtmlExtension = oRE.Test(sExt)
309
Private Function SniffHtml( sData )
313
oRE.IgnoreCase = True
317
aPatterns = Array( "<!DOCTYPE\W*X?HTML", "<(body|head|html|img|pre|script|table|title)", "type\s*=\s*[\'""]?\s*(?:\w*/)?(?:ecma|java)", "(?:href|src|data)\s*=\s*[\'""]?\s*(?:ecma|java)script:", "url\s*\(\s*[\'""]?\s*(?:ecma|java)script:" )
320
For i = 0 to UBound( aPatterns )
321
oRE.Pattern = aPatterns( i )
322
If oRE.Test( sData ) Then
332
' Thanks to http://www.ericphelps.com/q193998/index.htm
333
Private Function ByteArray2Text(varByteArray)
334
Dim strData, strBuffer, lngCounter
337
For lngCounter = 0 to UBound(varByteArray)
338
strBuffer = strBuffer & Chr(255 And Ascb(Midb(varByteArray,lngCounter + 1, 1)))
339
'Keep strBuffer at 1k bytes maximum
340
If lngCounter Mod 1024 = 0 Then
341
strData = strData & strBuffer
345
ByteArray2Text = strData & strBuffer
350
Class NetRube_FileInfo
351
Dim FormName, ClientPath, Path, Name, Ext, Content, Size, MIME, Start