When we write the file upload code, we also need to consider an important implementation function, that is the file upload required progress bar. Now I knowHere are two examples to be implemented separately for reference, more flexible applications to modify according to their own needs.
APC php File Upload progress bar 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:
- 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:
Implementation of the PHP file upload progress bar for installing the module using the PECL module installation method
PHP.ini inside set uploadprogress.file.filename_template = "/tmp/upd_%s.txt"
code example:
- 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
- }
These are the two types of PHP files that we introduced to upload progress bar specific methods.
http://www.bkjia.com/PHPjc/446391.html www.bkjia.com true http://www.bkjia.com/PHPjc/446391.html techarticle when we write the file upload code, we also need to consider an important implementation function, that is the file upload required progress bar. At the moment I know I'm here to give you two different implementations ...