Heim  >  Artikel  >  php教程  >  PHP配合apc实现上传进度条

PHP配合apc实现上传进度条

WBOY
WBOYOriginal
2016-06-21 08:50:53916Durchsuche

 

PHP配合apc实现上传进度条, 一直以为PHP是无法做到进度条一个动态的功能,原来还是自己的知识面不够,看到了apc扩展相关的一些文章,利用apc扩展达到了动态实现效果。根据找到相关的文章自己并在此基础上做了一些小修改。自己的服务器用的window,在这里主要针对的是window上的应用。
1.服务器要支持apc扩展,没有此扩展的话,百度一下php_apc.dll ,下载一个扩展扩展要求php.5.2以上。
2.配置apc相关配置,重启apache

PHP Code

  1. extension=php_apc.dll  
  2. apc.rfc1867 = on  
  3. apc.max_file_size = 1000M  
  4. upload_max_filesize = 1000M  
  5. post_max_size = 1000M  

 

说明一下:至于参数要配多大,得看项目需要apc.max_file_size,  设置apc所支持上传文件的大小,要求apc.max_file_size 3.在代码里面利用phpinfo();查看apc扩展安装了没有。
4.下面是实现代码:
getprogress.php

PHP Code

  1. session_start();  
  2. if(isset($_GET['progress_key'])) {  
  3.   $status = apc_fetch('upload_'.$_GET['progress_key']);  
  4.   echo ($status['current']/$status['total'])*100;  
  5. }  
  6. ?>  

upload.php

PHP Code

  1.    $id = $_GET['id'];  
  2. ?>  
  3.   
  4.        id="progress_key"  value=""/>  

  5.   
  6.  type="submit" value="上传"/>  
  7.   


target.php

PHP Code

  1. set_time_limit(600);  
  2. if($_SERVER['REQUEST_METHOD']=='POST') {  
  3.   move_uploaded_file($_FILES["test_file"]["tmp_name"],   
  4.   dirname($_SERVER['SCRIPT_FILENAME'])."/UploadTemp/" . $_FILES["test_file"]["name"]);//UploadTemp文件夹位于此脚本相同目录下  
  5.   echo "

    上传成功

    ";  
  6. }  
  7. ?>  

index.php

PHP Code

  1.    $id = md5(uniqid(rand(), true));  
  2. ?>  
  3.   
  4. 上传进度  
  5.   
  6. <script></script>  
  7.   
  8.   
  9. <script> </script>
  10. var proNum=0;  
  11. var loop=0;  
  12. var progressResult;  
  13. function sendURL() {  
  14.             $.ajax({  
  15.                         type : 'GET',  
  16.                         url : "getprogress.php?progress_key=",  
  17.                         async : true,  
  18.                         cache : false,  
  19.                         dataType : 'json',  
  20.                         data: "progress_key=",  
  21.                         success : function(e) {  
  22.                                      progressResult = e;  
  23.                                       proNum=parseInt(progressResult);  
  24.                                       document.getElementById("progressinner").style.width = proNum+"%";  
  25.                                       document.getElementById("showNum").innerHTML = proNum+"%";  
  26.                                       if ( proNum 
  27.                                         setTimeout("getProgress()", 100);  
  28.                                       }   
  29.                                    
  30.                         }  
  31.             });  
  32.     
  33. }  
  34.   
  35. function getProgress(){  
  36.  loop++;  
  37.   
  38.  sendURL();  
  39. }  
  40. var interval;  
  41. function startProgress(){  
  42.     document.getElementById("progressouter").style.display="block";  
  43.    setTimeout("getProgress()", 100);  
  44. }  
  45.   
  46.   


  47.   
  48.   
  49.    
      
  

  •   
  •   
  •   
  •   


  • Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
    Vorheriger Artikel:还算功能比较全的PHP验证码类Nächster Artikel:linux ldap认证:windos 和 linux 下实现PHP和LDAP身份认证

    In Verbindung stehende Artikel

    Mehr sehen