⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cls_uploadclass.asp

📁 后台管理系统
💻 ASP
📖 第 1 页 / 共 2 页
字号:
<%
'==============================================================================
'软件名称:拓网文件上传提取系统
'当前版本:拓网文件上传提取系统1.0(TopWang Upload V1.0)
'Copyright (C) 2003-2006 TopWang.Com  All rights reserved.
'产品咨询QQ:36355735
'程序开发:拓网产品开发组
'Email:Service@TopWang.Com
'官方网站:www.TopWang.com
'论坛支持:拓网在线论坛(http://bbs.TopWang.com)
'免费版本请在程序首页保留版权信息,并做上本站LOGO友情连接
'==============================================================================

'==============================================================================
'文件名:Cls_UpLoadClass.asp
'摘  要:无组件上传类,此类修改自风声无组件上传类
'作  者:拓网产品开发组
'更  新:2006-2-10
'==============================================================================
Class Cls_UploadClass
	Private p_MaxSize, p_TotalSize, p_FileType, p_SavePath, p_AutoSave, p_Error
	Private ObjForm, BinForm, BinItem, LngTime
	Public	FormItem, FileItem, StrDate, p_UpLoadPID
	' ============================================
	' 返回版本信息
	' ============================================
	Public Property Get Version
		Version = "拓网无组件上传类 Version 1.0"
	End Property
	' ============================================
	' 返回错误信息
	' ============================================
	Public Property Get Error
		Error = p_Error
	End Property
	' ============================================
	' 返回上传文件最大值 单个文件
	' ============================================
	Public Property Get MaxSize
		MaxSize = p_MaxSize
	End Property
	' ============================================
	' 设置上传文件最大值 单个文件
	' ============================================
	Public Property Let MaxSize(LngSize)
		If IsNumeric(LngSize) Then
			p_MaxSize = Clng(LngSize)
		End If
	End Property
	' ============================================
	' 返回上传文件最大值 全局
	' ============================================
	Public Property Get TotalSize
		TotalSize = p_TotalSize
	End Property
	' ============================================
	' 设置上传文件最大值 全局
	' ============================================
	Public Property Let TotalSize(LngSize)
		If IsNumeric(LngSize) Then
			p_TotalSize = Clng(LngSize)
		End If
	End Property
	' ============================================
	' 返回允许上传的文件类型 扩展名
	' ============================================
	Public Property Get FileType
		FileType = p_FileType
	End Property
	' ============================================
	' 设置允许上传的文件类型 扩展名
	' ============================================
	Public Property Let FileType(strType)
		p_FileType = strType
	End Property
	' ============================================
	' 返回文件保存路径
	' ============================================
	Public Property Get SavePath
		SavePath = p_SavePath
	End Property
	' ============================================
	' 设置文件保存路径
	' ============================================
	Public Property Let SavePath(StrPath)
		p_SavePath = Replace(StrPath, chr(0), "")
	End Property
	' ============================================
	' 返回自动保存文件
	' ============================================
	Public Property Get AutoSave
		AutoSave = p_AutoSave
	End Property
	' ============================================
	' 设置文件保存路径
	' ============================================
	Public Property Let UpLoadPID(PID)
		p_UpLoadPID = PID
	End Property
	Public Property Get UpLoadPID()
		UpLoadPID = p_UpLoadPID
	End Property
	' ============================================
	' 设置Open方法处理文件的方式,对其他方法无效
	' ============================================
	Public Property Let AutoSave(byVal Flag)
		Select Case Flag
			Case 0 ' 取无重复的服务器时间字符串为文件名自动保存文件
			Case 1 ' 取源文件名自动保存文件
			Case 2 ' 不自动保存文件,Open之后请用Save/GetData方法保存文件
			Case False Flag = 2
			Case Else Flag = 0
		End Select
		p_AutoSave = Flag
	End Property
	' ============================================
	' 类初始化
	' ============================================
	Private Sub Class_Initialize
		p_Error	    = -1
		p_MaxSize   = 1536000 ' 单位:字节
		p_FileType  = "gif/jpg/jpeg/bmp/png/rar/txt/zip/mid"
		p_SavePath  = "UploadFile/"
		p_AutoSave  = 0
		p_TotalSize = 536870912 ' 这里直接设置为500M,不必在类中构建接口了。
		StrDate	    = ClsPub.CreateId(1,5)
		Randomize Timer()
		LngTime	    = Clng(10000 + Rnd() * 89999)
		' 生成上传ID编号
		p_UpLoadPID = StrDate & LngTime
		Set BinForm = Server.CreateObject(ServerObject_003)
		Set BinItem = Server.CreateObject(ServerObject_003)
		Set ObjForm = Server.CreateObject(ServerObject_004)
		ObjForm.CompareMode = 1
	End Sub
	' ============================================
	' 类结束
	' ============================================
	Private Sub Class_Terminate
		On Error Resume Next
		ObjForm.RemoveAll
		Set ObjForm = Nothing
		Set BinItem = Nothing
		If p_Error <> 4 Then BinForm.Close()
		Set BinForm = Nothing
	End Sub
	' ============================================
	' 打开对象,打开之前可以重定义对象参数属性MaxSize等
	' ============================================
	Public Sub Open()
		If p_Error = -1 Then
			p_Error = 0
		Else
			Exit Sub
		End If
		Dim LngRequestSize, LngReadSize, BinRequestData, StrFormItem, StrFileItem ,p_ChunkByte, IntTemp, StrTemp
		Const StrSplit = "'"">"
		LngRequestSize = Request.TotalBytes
		If (LngRequestSize < 1) Or ((LngRequestSize > p_TotalSize) And p_TotalSize <> 0) Then
			p_Error = 4
			Exit Sub
		End If
		BinForm.Type = 1
		BinForm.Open
		LngReadSize = 0
		p_ChunkByte = 102400
		BinItem.Type = 2
		BinItem.Charset = "GB2312"
		BinItem.Open
		Response.Flush()
		Do
			On Error Resume Next
			BinForm.Write Request.BinaryRead(p_ChunkByte)
			LngReadSize = LngReadSize + p_ChunkByte
			If  LngReadSize >= LngRequestSize Then Exit Do
			BinItem.WriteText "lngTotalSize=" & LngRequestSize & ";lngReadSize=" & LngReadSize & ";"
			BinItem.SaveToFile Server.MapPath("UpLoadData/" & p_UpLoadPID & ".js"), 2
			Response.flush()
		Loop
		BinItem.WriteText "lngTotalSize=" & LngRequestSize & ";lngReadSize=" & LngReadSize & ";"
		BinItem.SaveToFile Server.MapPath("UpLoadData/" & p_UpLoadPID & ".js"), 2
		BinItem.Close()
		Response.Flush()
		BinForm.Position = 0
		BinRequestData = BinForm.Read()

		Dim bCrLf, StrSeparator, IntSeparator
		bCrLf = ChrB(13) & ChrB(10)

		IntSeparator = InStrB(1, BinRequestData, bCrLf)-1
		StrSeparator = LeftB(BinRequestData, IntSeparator)

		Dim p_Start, p_End, StrItem, StrInam
		Dim StrFtyp, StrFnam, StrFext, LngFsiz
		p_Start = IntSeparator + 2
		Do
			p_End  = InStrB(p_Start, BinRequestData, bCrLf & bCrLf) + 3
			BinItem.Type=1
			BinItem.Open
			BinForm.Position = p_Start
			BinForm.CopyTo BinItem, p_End - p_Start
			BinItem.Position = 0
			BinItem.Type = 2
			BinItem.Charset = "GB2312"
			StrItem = BinItem.ReadText
			BinItem.Close()

			p_Start = p_End
			p_End  = InStrB(p_Start, BinRequestData, StrSeparator)-1
			BinItem.Type = 1
			BinItem.Open
			BinForm.Position = p_Start
			LngFsiz = p_End-p_Start-2
			BinForm.CopyTo BinItem, LngFsiz

			IntTemp = InStr(39, StrItem, """")
			StrInam = Mid(StrItem, 39, IntTemp-39)

			If InStr(IntTemp, StrItem, "filename=""") <> 0 Then
				If Not ObjForm.Exists(StrInam & "_From") Then
					StrFileItem = StrFileItem & StrSplit & StrInam
					If BinItem.Size <> 0 Then
						IntTemp = IntTemp + 13
						StrFtyp = Mid(StrItem, InStr(IntTemp, StrItem, "Content-Type: ") + 14)
						StrTemp = Mid(StrItem, IntTemp, InStr(IntTemp, StrItem, """") - IntTemp)
						IntTemp = InStrRev(StrTemp, "\")
						StrFnam = Mid(StrTemp, IntTemp + 1)
						ObjForm.Add StrInam & "_Type", Replace(StrFtyp, vbCrLF, "")
						ObjForm.Add StrInam & "_Name", StrFnam
						ObjForm.Add StrInam & "_Path", Left(StrTemp, IntTemp)
						ObjForm.Add StrInam & "_Size", LngFsiz
						If InStr(IntTemp, StrTemp, ".") <> 0 Then
							StrFext = Mid(StrTemp, InStrRev(StrTemp, ".") + 1)
						Else
							StrFext = ""
						End If
						If Left(StrFtyp, 6) = "image/" Then
							BinItem.Position = 0
							BinItem.Type = 1
							StrTemp = BinItem.Read(10)
							' 更改了原来的判断方法,兼容性更强

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -