Upload the progress bar real-time reflection upload situation

Source: Internet
Author: User
Tags file upload file upload progress bar min reflection 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 (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" ><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> KB of

<span id=bytestotal></span> KB uploaded) </font></td>

</tr>

<tr>

<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" >

Transfer Speed:</font></td>

<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" >

<span id=bytespersecond></span> kb/sec </font></td>

</tr>

<tr>

<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" > Information:</font></td>

<td><font face= "Verdana, Arial, Helvetica, Sans-serif" size= "1" ><span id=information></span> </font></td>

</tr>

</table>

</td>

</tr>

<tr></tr>

</table>

</div>

<iframe name= "Up" style= "Display:none" ></iframe>

</form>



</body>




Progressbar.asp (return file for upload status data)



<% @EnableSessionState =false%>

<%

On Error Resume Next

Set theprogress = Server.CreateObject ("abcupload4.xprogress") ' Create Upload Component Object

Theprogress.id = Request.QueryString ("ID")

' Outputs the returned data in XML format

%>

<?xml version= "1.0" encoding= "gb2312"?>

<plan>

<PercentDone><%=theProgress.PercentDone%></PercentDone>

<min><%=int (THEPROGRESS.SECONDSLEFT/60)%></min>

<secs><%=theprogress.secondsleft Mod 60%></secs>

<bytesdone><%=round (theprogress.bytesdone/1024, 1)%></bytesdone>

<bytestotal><%=round (theprogress.bytestotal/1024, 1)%></bytestotal>

<bytespersecond><%=round (theprogress.bytespersecond/1024, 1)%></bytespersecond>

<Information><%=theProgress.Note%></Information>

</plan>



progressupload.asp (process upload file)



<% @EnableSessionState =false%>

<%

Response.Expires =-10000

Server.ScriptTimeout = 300



Set theform = Server.CreateObject ("Abcupload4.xform")

Theform.overwrite = True

Theform.maxuploadsize = 8000000

Theform.id = Request.QueryString ("ID")

Set Thefield = theform ("Filefield1") (1)

If thefield.fileexists Then

Thefield.save Thefield.filename

End If

%>




<body>

Transfer end

</body>






For other components to upload, the principle is similar, but the method is not the same.

I hope you have any comments and suggestions and I contact:

Junminliu@msn.com


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.