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:
Copy CodeThe 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 Ajax calls in the user-side page, please find the relevant documents 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 a form, 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 CodeThe 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 successful
} else {
Upload failed
} 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
}
http://www.bkjia.com/PHPjc/318577.html www.bkjia.com true http://www.bkjia.com/PHPjc/318577.html techarticle now I know two ways, one is to use the PHP founder Rasmuslerdorf write the APC extension module to implement (HTTP://PECL.PHP.NET/PACKAGE/APC), another way is to use the PECL expansion ...