加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP借助APC模块实现大文件上传进度条的方法

发布时间:2022-06-13 16:53:56 所属栏目:PHP教程 来源:互联网
导读:这篇文章主要介绍了PHP利用APC模块实现大文件上传进度条的方法,并分享了相关配置说明,感兴趣的朋友可以学习借鉴。 在使用apc时候,先必须使用安装apc 模块。 第一步:下载php_apc.dll 第二步:让php.ini支持apc扩展模块。 将php_apc.dll放入你的ext目录,
  这篇文章主要介绍了PHP利用APC模块实现大文件上传进度条的方法,并分享了相关配置说明,感兴趣的朋友可以学习借鉴。
 
 
  在使用apc时候,先必须使用安装apc 模块。
 
  第一步:下载php_apc.dll
 
  第二步:让php.ini支持apc扩展模块。
 
  将php_apc.dll放入你的ext目录,然后打开php.ini 加入:
 
  extension=php_apc.dll
 
  apc.rfc1867 = on
 
  apc.max_file_size = 100M
 
  upload_max_filesize = 100M
 
  post_max_size = 100M
 
  //以上参数可自己定义
 
  第三步:检查是否支持PHP APC
 
  if (function_exists('apc_fetch')) {
  echo 'it surpport apc model!';
  } else {
  echo "it's not support apc model!";
  }
  下面进入正题:
 
  原理:通过APC 模块,用ajas从缓存中读取上传的进度,详见:
 
  index.php
 
  <?php
   $unid=uniqid("");//确定唯一标致,实现多人同时上传
  ?>
  <div class="userinput2">
   <div id="captions">先将你要上传的软件上传服务器,上传时请耐心等候...<span class="style1"><br />
   </span>
   <script type="text/javascript" >
   var xmlHttp;
   var proNum=0;
    }
   xmlHttp=createxml();
   //ajas操作
   function sendURL() {
   var url="getprogress.php?progress_key=<?php echo $unid;?>";
   xmlHttp.open("GET",url,false);
   if (window.navigator.userAgent.indexOf("Firefox")>=1){
   //如果是firefox3.0
   xmlHttp.send("progress_key=<?php echo $unid;?>");
   if(xmlHttp.status==200) doHttpReadyStateChange();
     
   }else{
   xmlHttp.onreadystatechange = doHttpReadyStateChange;
   xmlHttp.send("progress_key=<?php echo $unid;?>");
   }
   }
   //回调函数
   function doHttpReadyStateChange() {
   if (xmlHttp.readyState== 4){
   proNum=parseInt(xmlHttp.responseText);
   //alert(proNum);
   document.getElementByIdx_x("progressinner").style.width = proNum+"%";
   document.getElementByIdx_x("showNum").innerHTML = proNum+"%";
   if ( proNum < 100){
   setTimeout("sendURL()", 200);
   }else{
   //上传成功后,还不能及时得到信息。还希望高人指点
   document.getElementByIdx_x("progressouter").style.display="none";
   document.getElementByIdx_x("progressinner").style.display="none";
   document.getElementByIdx_x("showNum").style.display="none";
   document.getElementByIdx_x("theframe").style.display="none";
   document.getElementByIdx_x("link2").style.display="block";
   }
     
   }
   }
   function startProgress(){
   document.getElementByIdx_x("progressouter").style.display="block";
   setTimeout("sendURL()", 200);
   }
    <br>
   <font size=2>文件下载地址为:</font><br />
   <input type=text name='link' id='link' style='width:380px;' />
   </div>
   <br/>
   <div id="progressouter" style="width: 500px; height: 20px; border: 1px solid #000000; display:none;">
   <div id="progressinner" style="position: relative; height: 20px; background-color: #333333; width: 0%; "></div>
   </div>
   <div id='showNum' style="font-size:12px; color:#333333"></div>
   </div>
  </div>
  softupload.php
 
  <?php
   $id = $_GET['id'];
  ?>
  <script language="javascript">
  //Trim the input text
  function Trim(input)
  {
   var lre = /^s*/;
   var rre = /s*$/;
   input = input.replace(lre, "");
   input = input.replace(rre, "");
   return input;
    //getting the file name
   while (fileName.indexOf("") != -1)
   fileName = fileName.slice(fileName.indexOf("") + 1);
   
   //Getting the file extension   
   var ext = fileName.slice(fileName.indexOf(".")).toLowerCase();
   for (var i = 0; i < extArray.length; i++)
   {
   if (extArray[i] == ext)
   {
   window.parent.startProgress(); return true;
   }
   }
   alert("正确的文件格式为" + (extArray.join(" ")) + "n请选择一个新的 " + "文件提交上传.");
   file.focus();
   return false;  
   }  
  </script> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  <form enctype="multipart/form-data" id="upload_form" action="target.php" method="POST">
  <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $id?>"/>
  <table width="322" border="0" cellpadding="0" cellspacing="0" id="linkTable">
   
   <tr>
   <td >1.选择软件<br />
   
   <input name="Softfile" type="file" id="Softfile" /></td>
   <td ><br />
   <input name="submit" type="submit" onclick="return CheckForTestFile();" value="上传软件"/></td>
   </tr>
   </table>
  </form> 

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读