There are two ways I know now, one is to use the APC extension (HTTP://PECL.PHP.NET/PACKAGE/APC) written by the founder of Php Rasmus Lerdorf, and the other is to use the PECL extension module Uploadprogress implementation (http://pecl.php.net/package/uploadprogress) I'll give you two examples to implement separately for reference, more flexible applications to modify according to their own needs.
APC Implementation method:
Install APC, refer to the Official document installation, you can use the Pecl module installation method quick and simple, here does not explain
Configure the php.ini, set the parameter apc.rfc1867=1, enable APC to support the upload progress bar function, in the APC source code document contains the description
code example:
The code is as follows:
if ($_server[' request_method ' = = ' POST ') { //upload request $status = Apc_fetch (' upload_ '. $_post[' Apc_upload_ PROGRESS ']); $status [' done '] = 1; echo Json_encode ($status); Output to the user-side page Ajax calls, related documents please look for exit, } elseif (Isset ($_get[' Progress_key ')) { //Read upload progress $status = APC _fetch (' Upload_ '. $_get[' Progress_key '); echo Json_encode ($status); Exit; } else { //other code, such as upload form }
Uploadprogress Module Implementation method:
Install the module using the PECL module installation method
PHP.ini inside set uploadprogress.file.filename_template = "/tmp/upd_%s.txt"
code example:
The code is as follows:
if ($_server[' Request_method ']== ' POST ') {if (Is_uploaded_file ($_files[' upfile ' [' tmp_name '])) {$upload _dir = ' your_path/'; $ext = STRRCHR ($_files[' video ' [' Name '], '. '); $sessid = $_post[' upload_identifier '); $tmpfile = $upload _dir. $sessid; $sessfile = $upload _dir. $sessid. $ext; if (Move_uploaded_file ($_files[' upfile ' [' tmp_name '], $tmpfile)) {//upload succeeded} else {//upload lost Fail} else {///Upload Error} elseif (!empty ($_get[' sessid ')) {header ("Expires:mon, Jul 1997 05:00:00 GMT" ); Header ("last-modified:".) Gmdate ("D, D M Y h:i:s"). "GMT"); Header ("Cache-control:no-store, No-cache, must-revalidate"); Header ("Cache-control:post-check=0, pre-check=0", false); Header ("Pragma:no-cache"); Header ("Content-type:text/html;charset=utf-8"); $unique _id = $_get[' sessid '); $uploadvalues = Uploadprogress_get_info ($unique _id); if (is_aRray ($uploadvalues)) {echo json_encode ($uploadvalues); else {//Read progress failed, additional processing logic}} else {//Show upload form}