<%@ EnableSessionState = False %>
<%
'=========================================================
' 文件：iXs_UpLoadAspUp3.asp
' 功能：用于输出AspUpload 进度数据
' 版本：爱雪儿图文管理系统 PAMS Version 1.1.0
' 时间：2006-01-05
' 作者：Guidy
' 版权：爱雪儿工作室 [iXuEr Studio]
'=========================================================
' Copyright (C) 2005-2008 iXuEr.Net All Rights Reserved .
' 官方网站：http://www.ixuer.net/
' 技术论坛：http://bbs.ixuer.net/
' 电子信箱：guidy@114xp.cn
'=========================================================
Response.Expires = -1

Dim UploadPID
UploadPID = Trim(Request.QueryString("UploadPID"))

' AspUpload 进度数据输出
' 说明：不直接读取完成百分比是为了在客户端脚本中兼容无组件上传类的读取方法
Dim UploadProgress
' 因为单位的关系所以需要转换一下
Dim oTs, oRs, oPs
Dim Format, Bar_Content
Set UploadProgress = Server.CreateObject("Persits.UploadProgress")

Format = "%V" ' 获取总大小 转换成字节
oTs = FormatSize(UploadProgress.FormatProgress(UploadPID, 10, "", Format))
Format = "%U" ' 获取当前大小 转换成字节
oRs = FormatSize(UploadProgress.FormatProgress(UploadPID, 10, "", Format))
Format = "%P" ' 获取上传进度 如果进度时100%，则强制当前大小等于总大小，以避免进度条长时间不关闭
oPs = CInt(RegExpSearch("\d+(\.)?\d+", UploadProgress.FormatProgress(UploadPID, 10, "", Format), 0, ""))
' 到达100不太准确，稍微小一点也不影响效果
If oPs >= 99 Then
	oRs = oTs
End If
Bar_Content = "lngTotalSize=" & oTs & ";lngReadSize=" & oRs & ";"
Response.Write(Bar_Content)
Response.Flush()
Set UploadProgress = Nothing
' ============================================
' 格式化文件大小，转换成字节
' ============================================
Function FormatSize(tSize)
	FormatSize = 0
	' 清理其中可能存在的HTML标记
	tSize = RegExpFilter("<.+?>", tSize, 1, "")
	' 按照不同的大小规则来转换
	If InStr(UCase(tSize), "G") > 0 Then
		FormatSize = Abs(RegExpSearch("\d+(\.)?\d+", tSize, 0, "")) * 1024 * 1024 * 1024
	ElseIf InStr(UCase(tSize), "M") > 0 Then
		FormatSize = Abs(RegExpSearch("\d+(\.)?\d+", tSize, 0, "")) * 1024 * 1024
	ElseIf InStr(UCase(tSize), "K") > 0 Then
		FormatSize = Abs(RegExpSearch("\d+(\.)?\d+", tSize, 0, "")) * 1024
	End If
End Function
' ============================================
' 按照指定的正则表达式替换字符
' ============================================
Public Function RegExpFilter(Patrn, Str, sType, ReplaceWith)
	Dim RegEx
	Set RegEx = New RegExp
	If sType = 1 Then
		RegEx.Global = True
	Else
		RegEx.Global = False
	End If
	RegEx.Pattern = Patrn
	RegEx.IgnoreCase = True
	RegExpFilter = RegEx.Replace(Str, ReplaceWith)
End Function
' ============================================
' 按照指定的正则表达式返回字符
' ============================================
Public Function RegExpSearch(Patrn, Str, sType, Spacer)
	Dim RegEx, Match, Matches , RetStr, i
	i = 0
	Set RegEx = New RegExp
	RegEx.Pattern = Patrn
	RegEx.IgnoreCase = True
	RegEx.Global = True
	Set Matches = RegEx.Execute(Str)
	For Each Match In Matches
		i = i + 1
		If sType = 0 Then
			RetStr = RetStr & Match.Value
			If i < Matches.Count Then RetStr = RetStr & Spacer
		Else
			RetStr = RetStr & Match.Value
			If i < Matches.Count Then RetStr = RetStr & Spacer
			If sType = i Then Exit For
		End If
	Next
	RegExpSearch = RetStr
End Function
%>