选择显示字体大小

上传的进度条 实时反映上传情况

      asp中使用组件上传时,有点麻烦就是不知道上传进度是多少,虽然有的提供了上传进度条,例如abcupload(下载地址:http://www.websupergoo.com)已经提供了显示当前上传状态的方法, 里面就有专门的实例(在安装目录的examples下面的progressupload.htm),它是提交数据的同时弹出一个反映进度的页面(progressbar.asp),然后通过这个页面自刷新来每隔一点时间获取当时的上传状态,然后把它们显示出来,但是用页面自刷新的方法效率比较低,不不好调节刷新时间间隔(最小间隔为1秒),而且服务器端返回数据量大,所以不能很好的实时反映上传情况。在客户端使用javascript调用msxml对象和settimout方法去定时load一个xml文件可以实现无刷新定时获取服务器端数据,在这里可以让progressbar.asp输出xml格式的数据,然后供客户端load,仅返回必要的几个参数,这样:页面不刷新;传输的数据少,不需要把所有数据全传到客户端 ,只传输反映状态的数据,如果定时器设置的时间足够小,那么我们就可以"实时"看到上传的状况了。以下就以abcupload4为例来说明怎么来制作实时的文件上传进度条。

(注:我们在abcupload自带例子基础上改进。)

progressupload.htm(上传文件的前台提交,我们让进度条在这个里面显示)



<html>

<body>



<script language=&quot;javascript&quot;>

<!--

theuniqueid = (new date()).gettime() % 1000000000;

function s()    //让数据提交的同时执行显示进度条的函数

{

       bar();      //开始执行反映上传情况的函数

       document.myform.action = &quot;progressupload.asp?id=&quot; + theuniqueid;  //处理上传数据的程序

       document.myform.target=&quot;up&quot;  //将提交的数据放在一个名字是up隐藏的iframe里面处理,这样提交的页面就不会跳转到处理数据的页

       document.myform.submit();     //提交表单





}

function bar()

{

       bar1.style.display='';  //让显示上传进度显示的层的可见

       var timeoutid=null;        //这个变量是作定时器的id

    var oxmldoc = new activexobject('msxml');             //创建'msxml'对象

    surl = &quot;progressbar.asp?id=&quot; + theuniqueid + &quot;&temp=&quot;+math.random();      //获取上传状态数据的地址

    oxmldoc.url = surl;     //load数据

    var oroot=oxmldoc.root;     //获取返回xml数据的根节点

    if(oroot.children != null)  

    {

              if (oroot.children.item(0).text-100==0)              //文件上传结束就取消定时器

                     cleartimeout(timeoutid)

              percentdone.style.width=oroot.children.item(0).text+&quot;%&quot;;         //设置进度条的百分比例

              //根据返回的数据在客户端显示

              min.innerhtml=oroot.children.item(1).text;       //显示剩余时间(分钟)

              secs.innerhtml=oroot.children.item(2).text;       //显示剩余时间(秒钟)

              bytesdone.innerhtml=oroot.children.item(3).text;    //已上传数据大小

              bytestotal.innerhtml=oroot.children.item(4).text;    //总大小

              bytespersecond.innerhtml=oroot.children.item(5).text; //传输速率

              information.innerhtml=oroot.children.item(6).text;          //上传信息

    }

       if (oroot.children.item(0).text-100<0)  //只要文件没有传完,就每隔多少时间获取一次数据

              timeoutid = settimeout(&quot;bar()&quot;,50)      //这里设定时间间隔是0.05秒,你也可以根据你的情况修改获取数据时间间隔

}

//-->

</script>



<form name=&quot;myform&quot; method=&quot;post&quot; action=&quot;progressupload.asp&quot; enctype=&quot;multipart/form-data&quot; target=up>

<input type=&quot;file&quot; name=&quot;filefield1&quot;><br>

<input type=&quot;button&quot; name=&quot;dosubmit&quot; value=&quot;upload&quot; onclick=&quot;s()&quot;><br>

<div id=bar1 style=&quot;display:none&quot;>

<table border=&quot;0&quot; width=&quot;100%&quot;>

  <tr>

    <td><font face=&quot;verdana, arial, helvetica, sans-serif&quot; size=&quot;2&quot;><b>传送:</b></font></td>

  </tr>

  <tr bgcolor=&quot;#999999&quot;>

    <td>

      <table border=&quot;0&quot; width=&quot;&quot; cellspacing=&quot;1&quot; bgcolor=&quot;#0033ff&quot; id=percentdone>

        <tr>

          <td><font size=1>&nbsp;</font></td>

        </tr>

      </table>

    </td>

  </tr>

  <tr>

    <td>

      <table border=&quot;0&quot; width=&quot;100%&quot;>

        <tr>

          <td><font face=&quot;verdana, arial, helvetica, sans-serif&quot; size=&quot;1&quot;>剩余时间:</font></td>

          <td><font face=&quot;verdana, arial, helvetica, sans-serif&quot; size=&quot;1&quot;>

                 <span id=min></span> 分  

              <span id=secs></span> 秒

              (<span id=bytesdone></span> kb of

              <span id=bytestotal></span> kb 已上传)</font></td>

        </tr>

        <tr>

          <td><font face=&quot;verdana, arial, helvetica, sans-serif&quot; size=&quot;1&quot;>

              传送速度:</font></td>

          <td><font face=&quot;verdana, arial, helvetica, sans-serif&quot; size=&quot;1&quot;>

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

        </tr>

        <tr>

          <td><font face=&quot;verdana, arial, helvetica, sans-serif&quot; size=&quot;1&quot;>信息:</font></td>

          <td><font face=&quot;verdana, arial, helvetica, sans-serif&quot; size=&quot;1&quot;><span id=information></span></font></td>

        </tr>

      </table>

    </td>

  </tr>

  <tr></tr>

</table>

</div>

<iframe name=&quot;up&quot; style=&quot;display:none&quot;></iframe>

</form>



</body>

</html>



progressbar.asp(返回上传状况数据的文件)



<%@enablesessionstate=false%>

<%

on error resume next

set theprogress = server.createobject(&quot;abcupload4.xprogress&quot;)  '创建上传组件对象

theprogress.id = request.querystring(&quot;id&quot;)

'将返回数据以xml格式输出

%>

<?xml version=&quot;1.0&quot; encoding=&quot;gb2312&quot; ?>

<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(处理上传文件)



<%@enablesessionstate=false%>

<%

response.expires = -10000

server.scripttimeout = 300



set theform = server.createobject(&quot;abcupload4.xform&quot;)

theform.overwrite = true

theform.maxuploadsize = 8000000

theform.id = request.querystring(&quot;id&quot;)

set thefield = theform(&quot;filefield1&quot;)(1)

if thefield.fileexists then

       thefield.save thefield.filename

end if

%>



<html>

<body>

传送结束

</body>

</html>





对于其他组件上传,原理也就差不多了,只是方法不一样罢了。

希望大家有什么意见和建议和我联系:)

junminliu@msn.com


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons