Rev 1075 | Blame | Last modification | View Log | RSS feed
<!--* FCKeditor - The text editor for internet* Copyright (C) 2003-2006 Frederico Caldeira Knabben** Licensed under the terms of the GNU Lesser General Public License:* http://www.opensource.org/licenses/lgpl-license.php** For further information visit:* http://www.fckeditor.net/** "Support Open Source software. What about a donation today?"** File Name: class_upload.asp* These are the classes used to handle ASP upload without using third* part components (OCX/DLL).** File Authors:* NetRube (netrube@126.com)--><%'**********************************************' File: NetRube_Upload.asp' Version: NetRube Upload Class Version 2.1 Build 20050228' Author: NetRube' Email: NetRube@126.com' Date: 02/28/2005' Comments: The code for the Upload.' This can free usage, but please' not to delete this copyright information.' If you have a modification version,' Please send out a duplicate to me.'**********************************************' 文件名: NetRube_Upload.asp' 版本: NetRube Upload Class Version 2.1 Build 20050228' 作者: NetRube(网络乡巴佬)' 电子邮件: NetRube@126.com' 日期: 2005年02月28日' 声明: 文件上传类' 本上传类可以自由使用,但请保留此版权声明信息' 如果您对本上传类进行修改增强,' 请发送一份给俺。'**********************************************Class NetRube_UploadPublic File, FormPrivate oSourceDataPrivate nMaxSize, nErr, sAllowed, sDeniedPrivate Sub Class_InitializenErr = 0nMaxSize = 1048576Set File = Server.CreateObject("Scripting.Dictionary")File.CompareMode = 1Set Form = Server.CreateObject("Scripting.Dictionary")Form.CompareMode = 1Set oSourceData = Server.CreateObject("ADODB.Stream")oSourceData.Type = 1oSourceData.Mode = 3oSourceData.OpenEnd SubPrivate Sub Class_TerminateForm.RemoveAllSet Form = NothingFile.RemoveAllSet File = NothingoSourceData.CloseSet oSourceData = NothingEnd SubPublic Property Get VersionVersion = "NetRube Upload Class Version 1.0 Build 20041218"End PropertyPublic Property Get ErrNumErrNum = nErrEnd PropertyPublic Property Let MaxSize(nSize)nMaxSize = nSizeEnd PropertyPublic Property Let Allowed(sExt)sAllowed = sExtEnd PropertyPublic Property Let Denied(sExt)sDenied = sExtEnd PropertyPublic Sub GetDataDim aCTypeaCType = Split(Request.ServerVariables("HTTP_CONTENT_TYPE"), ";")If aCType(0) <> "multipart/form-data" ThennErr = 1Exit SubEnd IfDim nTotalSizenTotalSize = Request.TotalBytesIf nTotalSize < 1 ThennErr = 2Exit SubEnd IfIf nMaxSize > 0 And nTotalSize > nMaxSize ThennErr = 3Exit SubEnd IfoSourceData.Write Request.BinaryRead(nTotalSize)oSourceData.Position = 0Dim oTotalData, oFormStream, sFormHeader, sFormName, bCrLf, nBoundLen, nFormStart, nFormEnd, nPosStart, nPosEnd, sBoundaryoTotalData = oSourceData.ReadbCrLf = ChrB(13) & ChrB(10)sBoundary = MidB(oTotalData, 1, InStrB(1, oTotalData, bCrLf) - 1)nBoundLen = LenB(sBoundary) + 2nFormStart = nBoundLenSet oFormStream = Server.CreateObject("ADODB.Stream")Do While (nFormStart + 2) < nTotalSizenFormEnd = InStrB(nFormStart, oTotalData, bCrLf & bCrLf) + 3With oFormStream.Type = 1.Mode = 3.OpenoSourceData.Position = nFormStartoSourceData.CopyTo oFormStream, nFormEnd - nFormStart.Position = 0.Type = 2.CharSet = "UTF-8"sFormHeader = .ReadText.CloseEnd WithnFormStart = InStrB(nFormEnd, oTotalData, sBoundary) - 1nPosStart = InStr(22, sFormHeader, " name=", 1) + 7nPosEnd = InStr(nPosStart, sFormHeader, """")sFormName = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)If InStr(45, sFormHeader, " filename=", 1) > 0 ThenSet File(sFormName) = New NetRube_FileInfoFile(sFormName).FormName = sFormNameFile(sFormName).Start = nFormEndFile(sFormName).Size = nFormStart - nFormEnd - 2nPosStart = InStr(nPosEnd, sFormHeader, " filename=", 1) + 11nPosEnd = InStr(nPosStart, sFormHeader, """")File(sFormName).ClientPath = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)File(sFormName).Name = Mid(File(sFormName).ClientPath, InStrRev(File(sFormName).ClientPath, "\") + 1)File(sFormName).Ext = LCase(Mid(File(sFormName).Name, InStrRev(File(sFormName).Name, ".") + 1))nPosStart = InStr(nPosEnd, sFormHeader, "Content-Type: ", 1) + 14nPosEnd = InStr(nPosStart, sFormHeader, vbCr)File(sFormName).MIME = Mid(sFormHeader, nPosStart, nPosEnd - nPosStart)ElseWith oFormStream.Type = 1.Mode = 3.OpenoSourceData.Position = nPosEndoSourceData.CopyTo oFormStream, nFormStart - nFormEnd - 2.Position = 0.Type = 2.CharSet = "UTF-8"Form(sFormName) = .ReadText.CloseEnd WithEnd IfnFormStart = nFormStart + nBoundLenLoopoTotalData = ""Set oFormStream = NothingEnd SubPublic Sub SaveAs(sItem, sFileName)If File(sItem).Size < 1 ThennErr = 2Exit SubEnd IfIf Not IsAllowed(File(sItem).Ext) ThennErr = 4Exit SubEnd IfDim oFileStreamSet oFileStream = Server.CreateObject("ADODB.Stream")With oFileStream.Type = 1.Mode = 3.OpenoSourceData.Position = File(sItem).StartoSourceData.CopyTo oFileStream, File(sItem).Size.Position = 0.SaveToFile sFileName, 2.CloseEnd WithSet oFileStream = NothingEnd SubPrivate Function IsAllowed(sExt)Dim oRESet oRE = New RegExpoRE.IgnoreCase = TrueoRE.Global = TrueIf sDenied = "" ThenoRE.Pattern = sAllowedIsAllowed = (sAllowed = "") Or oRE.Test(sExt)ElseoRE.Pattern = sDeniedIsAllowed = Not oRE.Test(sExt)End IfSet oRE = NothingEnd FunctionEnd ClassClass NetRube_FileInfoDim FormName, ClientPath, Path, Name, Ext, Content, Size, MIME, StartEnd Class%>