There are two kinds of methods I know at the moment, one is implemented using the APC extension module written by the founder of PHP Rasmus Lerdorf (HTTP://PECL.PHP.NET/PACKAGE/APC), and the other is to use the PECL extension module Uploadprogress implementation (http://pecl.php.net/package/uploadprogress) Here are two examples of implementation, and more flexible applications are modified to suit their needs.
APC Implementation method:
Install APC, refer to official documentation installation, you can use the Pecl module installation method quickly and easily, here does not indicate
Configure php.ini, set parameters apc.rfc1867=1, enable APC support upload progress bar function, in the APC source code description document contains instructions
code example:
Copy Code code 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 Ajax calls in the client page, please find the documentation yourself
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 uploading forms, etc.
}
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:
Copy Code code 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 successful
} else {
Upload failed
} else {
Upload Error
} elseif (!empty ($_get[' sessid ')) {
Header ("Expires:mon, June June 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 failure, additional processing logic
}
} else {
Show Upload Form
}