<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<%
Dim Sundyupload_sourcedata
Class Sundyupload
Dim objform,objfile,version,objprogress
Dim xmlpath,charsetencoding
Public Function Form (strform)
Strform=lcase (Strform)
If not objform.exists (strform) Then
Form= ""
Else
Form=objform (Strform)
End If
End Function
Public Function File (strfile)
Strfile=lcase (strfile)
If not objfile.exists (strfile) Then
Set file=new FileInfo
Else
Set File=objfile (strfile)
End If
End Function
Public Sub Uploadinit (progressxmlpath,charset)
Dim Requestdata,sstart,crlf,sinfo,iinfostart,iinfoend,tstream,istart,thefile
Dim Ifilesize,sfilepath,sfiletype,sformvalue,sfilename
Dim Ifindstart,ifindend
Dim Iformstart,iformend,sformname
version= "Upload Width Progress Bar Version 1.0"
Set objform=server.createobject ("Scripting.Dictionary")
Set objfile=server.createobject ("Scripting.Dictionary")
If request.totalbytes<1 Then Exit Sub
Set Tstream = Server.CreateObject ("ADODB.stream")
Set sundyupload_sourcedata = Server.CreateObject ("ADODB.stream")
Sundyupload_sourcedata.type = 1
Sundyupload_sourcedata.mode =3
Sundyupload_sourcedata.open
Dim TotalBytes
Dim chunkreadsize
Dim Datapart, Partsize
Dim objprogress
TotalBytes = Request.TotalBytes ' Total size
Chunkreadsize = 64 * 1024 ' chunking size 64K
Bytesread = 0
Xmlpath = Progressxmlpath
Charsetencoding = CharSet
If charsetencoding = "" Then
charsetencoding = "Utf-8"
End If
Set objprogress = New Progress
Objprogress.progressinit (Xmlpath)
Objprogress.updateprogress totalbytes,0
' Circular chunking Read
Do While Bytesread < totalbytes
' Chunk-Reading
Partsize = Chunkreadsize
If partsize + bytesread > totalbytes Then partsize = Totalbytes-bytesread
Datapart = Request.BinaryRead (partsize)
Bytesread = Bytesread + partsize
Sundyupload_sourcedata.write Datapart
Objprogress.updateprogress Totalbytes,bytesread
Loop
' Sundyupload_sourcedata.write Request.BinaryRead (request.totalbytes)
Sundyupload_sourcedata.position=0
RequestData =sundyupload_sourcedata.read
Iformstart = 1
Iformend = LenB (requestdata)
Crlf = ChrB (+) & ChrB (10)
Sstart = MidB (requestdata,1, InStrB (IFORMSTART,REQUESTDATA,CRLF)-1)
IStart = LenB (Sstart)
Iformstart=iformstart+istart+1
while (Iformstart +) < Iformend
Iinfoend = InStrB (Iformstart,requestdata,crlf & Crlf) +3
Tstream.type = 1
Tstream.mode =3
Tstream.open
Sundyupload_sourcedata.position = Iformstart
Sundyupload_sourcedata.copyto Tstream,iinfoend-iformstart
tstream.position = 0
Tstream.type = 2
Tstream.charset =charsetencoding
Sinfo = Tstream.readtext
Tstream.close
' Get form Item name
Iformstart = InStrB (Iinfoend,requestdata,sstart)
Ifindstart = InStr (22,sinfo, "name=" "", 1) +6
Ifindend = InStr (Ifindstart,sinfo, "" "", 1)
Sformname = LCase (Mid (Sinfo,ifindstart,ifindend-ifindstart))
' If it's a file
If InStr (45,sinfo, "filename=" "", 1) > 0 Then
Set thefile=new FileInfo
' Get filename
Ifindstart = InStr (Ifindend,sinfo, "filename=" "", 1) +10
Ifindend = InStr (Ifindstart,sinfo, "" "", 1)
sFileName = Mid (Sinfo,ifindstart,ifindend-ifindstart)
Thefile.filename=getfilename (sFileName)
Thefile.filepath=getfilepath (sFileName)
' Get file type
Ifindstart = InStr (Ifindend,sinfo, "Content-type:", 1) +14
Ifindend = InStr (IFINDSTART,SINFO,VBCR)
Thefile.filetype =mid (Sinfo,ifindstart,ifindend-ifindstart)
Thefile.filestart =iinfoend
Thefile.filesize = iformstart-iinfoend-3
Thefile.formname=sformname
If not objfile.exists (sformname) Then
Objfile.add Sformname,thefile
End If
Else
' If it is a form item
Tstream.type =1
Tstream.mode =3
Tstream.open
Sundyupload_sourcedata.position = Iinfoend
Sundyupload_sourcedata.copyto tstream,iformstart-iinfoend-3
tstream.position = 0
Tstream.type = 2
Tstream.charset = charsetencoding
Sformvalue = Tstream.readtext
Tstream.close
If objform.exists (sformname) Then
Objform (Sformname) =objform (sformname) & "," &sformvalue
Else
Objform.add Sformname,sformvalue
End If
End If
Iformstart=iformstart+istart+1
Wend
Requestdata= ""
Set Tstream = Nothing
End Sub
Private Sub Class_Initialize
End Sub
Private Sub Class_Terminate
If request.totalbytes>0 Then
Objform.removeall
Objfile.removeall
Set objform=nothing
Set objfile=nothing
Sundyupload_sourcedata.close
Set Sundyupload_sourcedata = Nothing
End If
Set objprogress = Nothing
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
If objfso.fileexists (Xmlpath) Then
objFSO.DeleteFile (Xmlpath)
End If
Set objFSO = Nothing
End Sub
Private Function GetFilePath (FullPath)
If fullpath <> "" Then
GetFilePath = Left (Fullpath,instrrev (FullPath, ""))
Else
GetFilePath = ""
End If
End Function
Private Function GetFileName (FullPath)
If fullpath <> "" Then
GetFileName = Mid (Fullpath,instrrev (FullPath, "") +1)
Else
GetFileName = ""
End If
End Function
End Class
Class FileInfo
Dim Formname,filename,filepath,filesize,filetype,filestart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
filestart= 0
FormName = ""
FileType = ""
End Sub
Public Function SaveAs (FullPath)
Dim Dr,errorchar,i
Saveas=true
' Response.Write FullPath & ' .....................<br> '
' Filename= ' ss.txt '
If trim (FullPath) = "" or filestart=0 or filename= "" or right (fullpath,1) = "/" Then Exit Function
' Response.Write ' 2........................<br> '
Set dr=createobject ("ADODB.stream")
Dr. Mode=3
Dr. Type=1
Dr. Open
Sundyupload_sourcedata.position=filestart
Sundyupload_sourcedata.copyto dr,filesize
Dr. SaveToFile fullpath,2
Dr. Close
Set dr=nothing
Saveas=false
End Function
End Class
Class Progress
Dim Objdom,xmlpath
Dim StartTime
Private Sub Class_Initialize
End Sub
Public Sub Progressinit (xmlpathtmp)
Dim Objroot,objchild
Dim OBJPI
Xmlpath = xmlpathtmp
Set objdom = Server.CreateObject ("Microsoft.XMLDOM")
Set objroot = objdom.createelement ("Progress")
Objdom.appendchild Objroot
Set objchild = objdom.createelement ("TotalBytes")
Objchild.text = "0"
Objroot.appendchild Objchild
Set objchild = objdom.createelement ("Uploadbytes")
Objchild.text = "0"
Objroot.appendchild Objchild
Set objchild = objdom.createelement ("Uploadpercent")
Objchild.text = "0%"
Objroot.appendchild Objchild
Set objchild = objdom.createelement ("Uploadspeed")
Objchild.text = "0"
Objroot.appendchild Objchild
Set objchild = objdom.createelement ("TotalTime")
Objchild.text = "00:00:00"
Objroot.appendchild Objchild
Set objchild = objdom.createelement ("Lefttime")
Objchild.text = "00:00:00"
Objroot.appendchild Objchild
Set OBJPI = objdom.createprocessinginstruction ("xml", "version= ' 1.0 ' encoding= ' utf-8 '")
Objdom.insertbefore Objpi, objdom.childnodes (0)
Objdom.save Xmlpath
Set OBJPI = Nothing
Set Objchild = Nothing
Set Objroot = Nothing
Set objdom = Nothing
End Sub
Sub UpdateProgress (tbytes,rbytes)
Dim etime,currenttime,speed,totaltime,lefttime,percent
If rbytes = 0 Then
StartTime = Timer
Set objdom = Server.CreateObject ("Microsoft.XMLDOM")
Objdom.load (Xmlpath)
Objdom.selectsinglenode ("//totalbytes"). Text=tbytes
Objdom.save (Xmlpath)
Else
Speed = 0.0001
CurrentTime = Timer
ETime = Currenttime-starttime
If etime>0 Then speed = Rbytes/etime
TotalTime = Tbytes/speed
Lefttime = (tbytes-rbytes)/speed
Percent = Round (rbytes *100/tbytes)
' Objdom.selectsinglenode ("//uploadbytes"). Text = Rbytes
' Objdom.selectsinglenode ("//uploadspeed"). Text = Speed
' Objdom.selectsinglenode ("//totaltime"). Text = TotalTime
' Objdom.selectsinglenode ("//lefttime"). Text = Lefttime
Objdom.selectsinglenode ("//uploadbytes"). Text = Formatfilesize (rbytes) & "/" & Formatfilesize (Tbytes)
Objdom.selectsinglenode ("//uploadpercent"). Text = percent
Objdom.selectsinglenode ("//uploadspeed"). Text = Formatfilesize (speed) & "/sec"
Objdom.selectsinglenode ("//totaltime"). Text = Sectotime (totaltime)
Objdom.selectsinglenode ("//lefttime"). Text = Sectotime (lefttime)
Objdom.save (Xmlpath)
End If
End Sub
Private Function Sectotime (sec)
Dim h:h = "0"
Dim m:m = "0"
Dim s:s = "0"
H = Round (sec/3600)
M = Round (sec mod 3600)/60)
s = Round (sec mod 60)
If LEN (h) =1 Then h = "0" & H
If LEN (m) =1 Then m = "0" & M
If LEN (s) =1 Then s = "0" & S
Sectotime = (H & ":" & M & ":" & S)
End Function
Private Function formatfilesize (fsize)
Dim radio,k,m,g,unittmp
K = 1024
m = 1024*1024
g = 1024*1024*1024
Radio = 1
If Fix (fsize/g) > 0.0 Then
unittmp = "GB"
Radio = g
ElseIf Fix (fsize/m) > 0 Then
unittmp = "MB"
Radio = M
ElseIf Fix (fsize/k) > 0 Then
unittmp = "KB"
Radio = k
Else
unittmp = "B"
Radio = 1
End If
If Radio = 1 Then
Formatfilesize = fsize & "&nbsp;" & unittmp
Else
Formatfilesize = FormatNumber (fsize/radio,3) & Unittmp
End If
End Function
Private Sub Class_Terminate
Set objdom = Nothing
End Sub
End Class
%>
<script language= "JavaScript Tutorial" >
Start progress bar
function Startprogress (Xmlpath) {
Displayprogress ();
Setprogressdivpos ();
SetTimeout ("Displayprogressbar (' + Xmlpath +") ", 500);
}
function Displayprogressbar (Xmlpath) {
var xmldoc = new ActiveXObject ("msxml2.domdocument.3.0");
Xmldoc.async = false;
Xmldoc.load (Xmlpath);
if (xmldoc.parseerror.errorcode!=0) {
var error = Xmldoc.parseerror;
Alert (Error.reason)
SetTimeout ("Displayprogressbar (' + Xmlpath +") ", 1000);
Return
}
var root = xmldoc.documentelement; Root node
var totalbytes = root.childnodes (0). text;
var uploadbytes = root.childnodes (1). text;
var percent = Root.childnodes (2). text;
progresspercent.innerhtml = percent + "%";
ProgressBar.style.width = percent + "%";
uploadsize.innerhtml = uploadbytes;
uploadspeed.innerhtml = Root.childnodes (3). text;
totaltime.innerhtml = Root.childnodes (4). text;
lefttime.innerhtml = Root.childnodes (5). text;
if (percent<100) {
SetTimeout ("Displayprogressbar (' + Xmlpath +") ", 1000);
}
}
function displayprogress () {
var objprogress = document.getElementById ("Progress");
ObjProgress.style.display = "";
}
function closeprogress () {
var objprogress = document.getElementById ("Progress");
ObjProgress.style.display = "None";
}
function Setprogressdivpos () {
var objprogress = document.getElementById ("Progress");
ObjProgress.style.top = document.body.scrolltop+ (Document.body.clientheight-document.getelementbyid ("Progress"). offsetheight)/2
ObjProgress.style.left = document.body.scrollleft+ (Document.body.clientwidth-document.getelementbyid ("Progress") . offsetwidth)/2;
}
</script>
<style type= "Text/css Tutorial" >
. Progress {
Position:absolute;
padding:4px;
top:50;
left:400;
Font-family:verdana, Helvetica, Arial, Sans-serif;
font-size:12px;
width:250px;
height:100px;
Background: #FFFBD1;
Color: #3D2C05;
border:1px solid #715208;
* Mozilla Proprietary * *
-moz-border-radius:5px;
/*-moz-opacity:0.95; */
}
. Progress Table,.progress td{
font-size:9pt;
}
. bar{
width:100%;
height:15px;
Background-color: #CCCCCC;
border:1px inset #666666;
margin-bottom:4px;
}
. progresspercent{
font-size:9pt;
Color: #000000;
height:15px;
Position:absolute;
z-index:20;
width:100%;
Text-align:center;
}
. progressbar{
Background-color: #91D65C;
width:1px;
height:15px;
}
</style>
<div id= "Progress" style= "Display:none" class= "Progress" >
<div class= "Bar" >
<div id= "progresspercent" class= "Progresspercent" >0%</div>
<div id= "ProgressBar" class= "ProgressBar" ></div>
</div>
<table border= "0" cellspacing= "0" cellpadding= "2" >
<tr>
<td> already uploaded </td>
<td>:</td>
<TD id= "Uploadsize" ></td>
</tr>
<tr>
<td> Upload Speed </td>
<td>:</td>
<TD id= "Uploadspeed" >&nbsp;</td>
</tr>
<tr>
<td> Total required Time </td>
<td>:</td>
<TD id= "TotalTime" >&nbsp;</td>
</tr>
<tr>
<td> remaining Time </td>
<td>:</td>
<TD id= "Lefttime" >&nbsp;</td>
</tr>
</table>
</div>
<% @LANGUAGE = "VBSCRIPT" codepage= "65001"%>
<!--#include file= "sundyupload.asp"-->
<%
' This example document encoding is UTF-8, if it is another encoded system, please convert the encoding to the appropriate encoding, otherwise the form gets the data may be garbled
Dim objupload,opt
Dim Xmlpath
Dim Fileformname,objfile,counter
opt = Request. QueryString ("opt")
If opt = "Upload" Then
Xmlpath = Server.MapPath (Request. QueryString ("Xmlpath")) ' converts a virtual path to a real path
Set objupload=new sundyupload ' Build upload Object
Objupload.uploadinit Xmlpath, "Utf-8"
Counter = 1
Response.Write ("plain form:" & Objupload.form ("Normalform") & "<BR><BR>") ' Get form data
For each fileformname in Objupload.objfile
Set Objfile=objupload.objfile (Fileformname)
FileSize = Objfile.filesize
strtemp= Objfile.filepath
Response.Write strtemp
FileName = Mid (Strtemp,instrrev (strtemp, "") +1)
' G0=
F0=replace (replace (now (), ":", ""), "", ""), "-", "" "&". " &g0
If fileSize > 0 Then
Response.Write ("File Size:" & fileSize & "<BR>")
Response.Write ("File Name:" & Objfile.filepath & "<BR>")
T=split (FileName, ".")
T1=t (1)
Filename=replace (replace (now, ":", ""), "", ""), "-", "" "&". " &t1
' Response.Write ("File Description:" & Objupload.form ("Filedesc" & Counter) & "<BR><BR>")
Objfile.saveas Server.MapPath (".") & "Upload" & FileName
Response.Write "Save at:" &server.mappath (".") & "Upload" & FileName & "<br><br>"
End If
Counter = counter + 1
Next
End If
' To upload a progress bar data file (the XML file specifies a virtual path)
' It's best to be random because it's possible for multiple people to upload at the same time and need different progress data
' This path needs to be passed in to the upload component at the time of submission to change the progress data during the upload process
' Client uses JavaScript to read this XML file, showing progress
Xmlpath = "upload/" & Timer & ". xml"
%>
<html>
<head>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>sundy Upload Progress Bar example</title>
<script language= "JavaScript" >
function Chkfrm () {
var objfrm = document.frmupload;
if (objfrm.file1.value== "" && objfrm.file2.value== "") {
Alert ("Please select a file");
ObjFrm.file1.focus ();
return false;
}
Objfrm.action = "example.asp?opt=upload&xmlpath=<%=xmlpath%>";
Startprogress (' <%=xmlPath%> ');//Start Progress bar
return true;
}
</script>
</head>
<body>
<form name= "Frmupload" method= "post" action= "example.asp" enctype= "Multipart/form-data" Onsubmit= "return chkfrm ()"
Plain form: <br><input type= "text" name= "Normalform" size= "><BR>" <br>
File 1:<br>
<input type= "file" Name= "File1" size= "></br>";
<input type= " Text "Name=" FILEDESC1 "size=" ><BR><BR>
file 2:<br>
<input type= "file" Name= "File2" Size= "></br>"
<input type= "text" name= "FILEDESC2" size= "><br>";
file 3:<br>
<input type= "File" Name= "File3" size= "></br>";
file 4:<br>
<input type= "file" Name= "File4" Size= "></br>"
file 5:<br>
<input type= "file" Name= "File5" size= "n" ></BR>
< Input type= "Submit" Name= "Btnsubmit" value= "submit"/>
</form>
</body>