ASP upload the progress bar real-time reflection upload situation

Source: Internet
Author: User
Tags file upload file upload progress bar min reflection return set time time interval client
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

(The front of the upload file is submitted, we let the progress bar show in this)
</P><P></P><P><script language= "javascript" ></P><P><!--</P>
<p>theuniqueid = (new Date ()). GetTime ()% 1000000000;</p><p>function s () file://performs a function that shows the progress bar while the data is submitted Lt;/p><p>{</p><p>
Bar (); FILE://starts performing functions that reflect uploads </P><P>
Document.myform.action = "progressupload.asp?id=" + Theuniqueid;
file://procedures for handling uploaded data </P><P>
document.myform.target= "Up" file://the submitted data in an IFRAME with a name that is up hidden, so that the submitted page does not jump to the page where the data is processed
Document.myform.submit (); file://submit the form </p><p></p><p></p><p>}
</p><p>function Bar () </P><P>{</P><P>
bar1.style.display=; file://lets show upload progress showing the layer's visible </P><P>
var timeoutid=null; file://This variable is used as a timer id</p><p>
var oxmldoc = new ActiveXObject (MSXML);
file://Create MSXML Objects </P><P>
sURL = "Progressbar.asp?id=" + Theuniqueid + "&temp=" +math.random ();
FILE://gets the address of the uploaded state data </P><P>
Oxmldoc.url = sURL;
File://load data
var oroot=oxmldoc.root;
file://gets the root node that returns the XML data
if (Oroot.children!= null) {
if (ORoot.children.item (0). text-100==0) file://Cancel the timer at the end of file upload
Cleartimeout (Timeoutid)
Percentdone.style.width=oroot.children.item (0). text+ "%"; file://to set the progress bar as a percentage example
file://is displayed on the client based on the returned data

Min.innerhtml=oroot.children.item (1). text; file://Show time remaining (minutes)

Secs.innerhtml=oroot.children.item (2). text; file://Show time remaining (seconds)

Bytesdone.innerhtml=oroot.children.item (3). text; file://uploaded data size

Bytestotal.innerhtml=oroot.children.item (4). text; Total size of file://

Bytespersecond.innerhtml=oroot.children.item (5). text; file://Transfer Rate

Information.innerhtml=oroot.children.item (6). text; file://Upload Information

}

if (ORoot.children.item (0). text-100<0) file://get data at every interval as long as the file is not sent out

Timeoutid = settimeout ("Bar ()", 50)

file://Here the time interval is 0.05 seconds, and you can modify the time interval to get the data according to your situation.

}</p><p>//--></p><p></script>nbsp; </tr></P><P>
</table></P><P> </td></P><P> </tr></P><P> <tr></p ><P><td></P><P>
<table border= "0" width= "100%" ></P><P><tr></P><P> <td><font face= " Verdana, Arial, Helvetica, Sans-serif "size=" 1 ">
Remaining Time:</font></td></p><p>
<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" ></P><P>
<span id=min></span> Minute </p><p><span id=secs></span> sec </P><P>
(<span id=bytesdone></span> KB of </p><p><span id=bytestotal></span> KB uploaded) </ Font></td></p><p>
</tr></P><P> <tr></P><P>
<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" ></P><P>
Transfer Speed:</font></td></p><p>
<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" ></P><P>
<span id=bytespersecond></span> kb/sec </font></td></P><P>
</tr></P><P> <tr></P><P>
<td><font face= "Verdana, Arial, Helve



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.