Upload ASP in the use of component upload, a little trouble is not know how much upload progress, although some provide upload progress bar, such as abcupload (download address: http:// Www.websupergoo.com has provided a way to display the current upload status, with a dedicated instance (progressupload.htm under the examples of the installation directory), which is to submit the data and pop up a page that reflects the progress (progressbar.asp) , and then through this page from the refresh to every little time to get the upload state, then show them, but with the page from the Refresh method efficiency is relatively low, not bad adjust the refresh interval (minimum interval of 1 seconds), and the server-side return data volume, so can not very good real-time reflection upload situation. Invoke the MSXML object and the Settimout method on the client using JavaScript to periodically load an XML file can obtain the server-side data without refreshing timing. Here you can let progressbar.asp output XML format data, and then for the client load, only return the necessary parameters, so that the page does not refresh, the transfer of less data, do not need to biography all the data to the client, only the reflection state of the data, if the timer set time is small enough, Then we can see the upload situation in real time. Take Abcupload4 as an example to illustrate how to make a real-time file upload progress bar.
(Note: We are improving on the basis of abcupload examples.) )
Progressupload.htm (front of the upload file, we let the progress bar show in this)
<body>
<script language= "JavaScript" >
<!--
Theuniqueid = (new Date ()). GetTime ()% 1000000000;
function s ()//enable data to be submitted while performing the functions that display the progress bar
{
Bar (); Start performing a function that reflects the upload
Document.myform.action = "progressupload.asp?id=" + Theuniqueid; Procedures for handling uploaded data
document.myform.target= "Up"///put the submitted data in an IFRAME with a name that is up hidden so that the submitted page does not jump to the page that processes the data
Document.myform.submit (); Submitting a form
}
function Bar ()
{
Bar1.style.display= '; Let the display upload progress show the layer visible
var timeoutid=null; This variable is the ID of the timer.
var oxmldoc = new ActiveXObject (' MSXML '); Create ' MSXML ' object
sURL = "Progressbar.asp?id=" + Theuniqueid + "&temp=" +math.random (); Get the address of the upload status data
Oxmldoc.url = sURL; Load data
var oroot=oxmldoc.root; Gets the root node that returns the XML data
if (Oroot.children!= null)
{
if (ORoot.children.item (0). text-100==0)//Cancel timer at end of file upload
Cleartimeout (Timeoutid)
Percentdone.style.width=oroot.children.item (0). text+ "%"; Set the percentage of progress bar example
Display on the client based on the returned data
Min.innerhtml=oroot.children.item (1). text; Show time remaining (minutes)
Secs.innerhtml=oroot.children.item (2). text; Show time remaining (seconds)
Bytesdone.innerhtml=oroot.children.item (3). text; Uploaded data size
Bytestotal.innerhtml=oroot.children.item (4). text; Total size
Bytespersecond.innerhtml=oroot.children.item (5). text; Transfer rate
Information.innerhtml=oroot.children.item (6). text; Upload Information
}
if (ORoot.children.item (0). text-100<0)///whenever the file is not finished, get the data at every interval
Timeoutid = settimeout ("Bar ()", 50)//Set time interval is 0.05 seconds, you can also modify the time interval to obtain data according to your situation
}
-->
</script>
<form name= "MyForm" method= "post" action= "progressupload.asp" enctype= "Multipart/form-data" target=up>
<input type= "File" Name= "Filefield1" ><br>
<input type= "button" Name= "Dosubmit" value= "Upload" onclick= "s ()" ><br>
<div id=bar1 style= "Display:none" >
<table border= "0" width= "100%" >
<tr>
<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "2" ><b> transmission:</b></font>< /TD>
</tr>
<tr bgcolor= "#999999" >
<td>
<table border= "0" width= "" cellspacing= "1" bgcolor= "#0033FF" id=percentdone>
<tr>
<td><font size=1> </font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border= "0" width= "100%" >
<tr>
<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" > Remaining time:</font></td>
<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" >
<span-Id=min></span>
<span id=secs></span> seconds
(<span id=bytesdone></span>