网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.制作我们自己的Ebay(拍卖系统)(1).
.天气预报的小偷,可以偷到全国24小.
.深入研究“用ASP上载文件”(二)&.
.一个基于web的QQ程序 2(xml+asp.
.动态显示图片的函数(显示广告条.
.ASP.NET数据库应用指南.
.简单ASP论坛DIY.
.“在线访客”的制作方法.
.在ASP中使用FSO组件生成HTML页面.
.ASP.NET发送ICQ信息DIY(2).
.网上“店铺”DIY(2).
.用SQL Server为Web浏览器提供图像.
.资料验证的asp.net程序.
.用ASP+XML打造留言本(2).
.ASP网站远程客户实现EXCEL打印功.
.ASP中的函数应用方法及应用举例(.
.通过事例学习.net的WebForms技术.
.DW+ASP 玩转动态二级菜单.
.用Agent+ASP技术制作语音聊天室.
.创建一个Web投票系统.

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

发表日期:2002-10-17


      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="javascript">

<!--

theUniqueID = (new Date()).getTime() % 1000000000;

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

{

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

       document.myform.action = "progressupload.asp?ID=" + theUniqueID;  //处理上传数据的程序

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

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





}

function bar()

{

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

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

    var oXMLDoc = new ActiveXObject('MSXML');             //创建'MSXML'对象

    sURL = "progressbar.asp?ID=" + theUniqueID + "&temp="+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+"%";         //设置进度条的百分比例

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

              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("bar()",50)      //这里设定时间间隔是0.05秒,你也可以根据你的情况修改获取数据时间间隔

}

//-->

</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>传送:</b></font></td>

  </tr>

  <tr bgcolor="#999999">

    <td>

      <table border="0" width="" cellspacing="1" bgcolor="#0033FF" id=PercentDone>

        <tr>

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

        </tr>

      </table>

    </td>

  </tr>

  <tr>

    <td>

      <table border="0" width="100%">

        <tr>

          <td><font face="Verdana, Arial, Helvetica, sans-serif" size="1">剩余时间:</font></td>

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

                 <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="Verdana, Arial, Helvetica, sans-serif" size="1">

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

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

              <span id=BytesPerSecond></span> KB/秒</font></td>

        </tr>

        <tr>

          <td><font face="Verdana, Arial, Helvetica, sans-serif" size="1">信息:</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>

</html>



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



<%@EnableSessionState=False%>

<%

On Error Resume Next

Set theProgress = Server.CreateObject("ABCUpload4.XProgress")  '创建上传组件对象

theProgress.ID = Request.QueryString("ID")

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

%>

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



<%@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

%>



<html>

<body>

传送结束

</body>

</html>





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

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

junminliu@msn.com

上一篇:用数组实现数据记录的批量录入方法 人气:14823
下一篇:用ASP动态生成JavaScript的表单验证代码 人气:17412
浏览全部上传的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐