php使用APC實(shí)現(xiàn)實(shí)時(shí)上傳進(jìn)度條功能
php不具備實(shí)時(shí)上傳進(jìn)度條功能,如果想有這種功能我們一般會(huì)使用ajax來(lái)實(shí)現(xiàn),但是php提供了一個(gè)apc,它就可以與php配置實(shí)現(xiàn)上傳進(jìn)度條功能。
主要針對(duì)的是window上的應(yīng)用。
1.服務(wù)器要支持apc擴(kuò)展,沒(méi)有此擴(kuò)展的話,下載一個(gè)擴(kuò)展擴(kuò)展要求php.5.2以上。
2.配置apc相關(guān)配置,重啟apache
代碼如下
extension=php_apc.dll
apc.rfc1867 = on
apc.max_file_size = 1000M
upload_max_filesize = 1000M
post_max_size = 1000M
說(shuō)明一下:至于參數(shù)要配多大,得看項(xiàng)目需要apc.max_file_size, 設(shè)置apc所支持上傳文件的大小,要求apc.max_file_size<=upload_max_filesize 并且apc.max_file_size <=post_max_size.重新啟動(dòng)apache即可實(shí)現(xiàn)apc的支持.
3.在代碼里面利用phpinfo();查看apc擴(kuò)展安裝了沒(méi)有。
4.下面是實(shí)現(xiàn)代碼:
getprogress.php
代碼如下
<?php session_start(); if(isset($_GET['progress_key'])) { $status = apc_fetch('upload_'.$_GET['progress_key']); echo ($status['current']/$status['total'])*100; } ?> upload.php PHP Code <?php $id = $_GET['id']; ?> <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?>"/> <input type="file" id="test_file" name="test_file"/><br/> <input onclick="window.parent.startProgress(); return true;" type="submit" value="上傳"/> </form>
target.php
代碼如下
<?php set_time_limit(600); if($_SERVER['REQUEST_METHOD']=='POST') { move_uploaded_file($_FILES["test_file"]["tmp_name"], dirname($_SERVER['SCRIPT_FILENAME'])."/UploadTemp/" . $_FILES["test_file"]["name"]);//UploadTemp文件夾位于此腳本相同目錄下 echo "<p>上傳成功</p>"; } ?>
index.php
代碼如下
<?php $id = md5(uniqid(rand(), true)); ?> <html> <head><title>上傳進(jìn)度</title></head> <body> <script src="js/jquery-1.4.4.min.js" language="javascript"></script> <script language="javascript"> var proNum=0; var loop=0; var progressResult; function sendURL() { $.ajax({ type : 'GET', url : "getprogress.php?progress_key=<?php echo $id;?>", async : true, cache : false, dataType : 'json', data: "progress_key=<?php echo $id;?>", success : function(e) { progressResult = e; proNum=parseInt(progressResult); document.getElementById("progressinner").style.width = proNum+"%"; document.getElementById("showNum").innerHTML = proNum+"%"; if ( proNum < 100){ setTimeout("getProgress()", 100); } } }); } function getProgress(){ loop++; sendURL(); } var interval; function startProgress(){ document.getElementById("progressouter").style.display="block"; setTimeout("getProgress()", 100); } </script> <iframe id="theframe" name="theframe" src="upload.php?id=<?php echo $id; ?>" style="border: none; height: 100px; width: 400px;" > </iframe> <br/><br/> <div id="progressouter" style="width: 500px; height: 20px; border: 6px solid red; display:none;"> <div id="progressinner" style="position: relative; height: 20px; background-color: purple; width: 0%; "></div> </div> <div id='showNum'></div><br> <div id='showNum2'></div> </body> </html>
以上就是跟大家分享的php使用APC實(shí)現(xiàn)實(shí)時(shí)上傳進(jìn)度條功能的方法,希望對(duì)大家的學(xué)習(xí)有所幫助。
- php ajax實(shí)現(xiàn)文件上傳進(jìn)度條
- PHP+apc+ajax實(shí)現(xiàn)的ajax_upload上傳進(jìn)度條代碼
- php實(shí)現(xiàn)簡(jiǎn)單的上傳進(jìn)度條
- PHP的APC模塊實(shí)現(xiàn)上傳進(jìn)度條
- PHP設(shè)置進(jìn)度條的方法
- PHP中使用Session配合Javascript實(shí)現(xiàn)文件上傳進(jìn)度條功能
- php+ajax實(shí)現(xiàn)帶進(jìn)度條的大數(shù)據(jù)排隊(duì)導(dǎo)出思路以及源碼
- ajax+php打造進(jìn)度條 readyState各狀態(tài)
- php 進(jìn)度條實(shí)現(xiàn)代碼
- PHP 文件上傳進(jìn)度條的兩種實(shí)現(xiàn)方法的代碼
- PHP+FLASH實(shí)現(xiàn)上傳文件進(jìn)度條相關(guān)文件 下載
- PHP實(shí)現(xiàn)的進(jìn)度條效果詳解
相關(guān)文章
PHP在innodb引擎下快速代建全文搜索功能簡(jiǎn)明教程【基于xunsearch】
這篇文章主要介紹了PHP在innodb引擎下快速代建全文搜索功能的方法,可基于開源搜索引擎xunsearch實(shí)現(xiàn),簡(jiǎn)明扼要的講述了安裝與使用的步驟與相關(guān)操作技巧,需要的朋友可以參考下2016-10-10PHP獲取中國(guó)時(shí)間(上海時(shí)區(qū)時(shí)間)及美國(guó)時(shí)間的方法
這篇文章主要介紹了PHP獲取中國(guó)時(shí)間(上海時(shí)區(qū)時(shí)間)及美國(guó)時(shí)間的方法,涉及php時(shí)區(qū)選擇及日期時(shí)間相關(guān)操作技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2017-02-02php function用法如何遞歸及return和echo區(qū)別
這篇文章主要介紹了php function用法如何遞歸及return和echo區(qū)別,需要的朋友可以參考下2014-03-03PHP判斷是否為空的幾個(gè)函數(shù)對(duì)比
這篇文章主要介紹了PHP判斷是否為空的幾個(gè)函數(shù)對(duì)比,本文講解了gettype()、empty()、is_null()、isset()等幾個(gè)函數(shù)在不同變量下的返回值情況,需要的朋友可以參考下2015-04-04php析構(gòu)函數(shù)的簡(jiǎn)單使用說(shuō)明
與構(gòu)造函數(shù)相反,在PHP5中,可以定義一個(gè)名為__destruct()的函數(shù),稱之為PHP5析構(gòu)函數(shù),PHP將在對(duì)象在內(nèi)存中被銷毀前調(diào)用析構(gòu)函數(shù),使對(duì)象在徹底消失之前完成一些工作。對(duì)象在銷毀一般可以通過(guò)賦值為null實(shí)現(xiàn)。2015-08-08ThinkPHP中調(diào)用PHPExcel的實(shí)現(xiàn)代碼
本文介紹ThinkPHP中處理導(dǎo)出成Excel文件的一個(gè)PHP庫(kù),PHPExcel。它可以很容易的生成出一個(gè)完整的、復(fù)雜的Excel文件,需要的朋友可以參考下2017-04-04