PHP is still more commonly used, so I studied the PHP upload file progress, here to take out and share with you, hope to be useful to everyone. PHP is very difficult to implement the upload progress bar is because when we upload files to the server, we have to wait until all the files are sent to the server, the corresponding PHP files are executed. Before that, the file data is stored in a temporary file, and PHP cannot get the path and size of the file.
Starting with ActionScript 2.0, Flash supports file uploads and downloads. Although it is not possible to get the file upload progress on the server, we can get the progress of sending the file on the server. According to this principle, flash can be used to make upload progress bar effect. I have seen some information on the internet, but I feel defective. So I studied it, on the basis of the predecessors to enhance the security and robustness of the program, and added some customizable parameters. There are two ways I know now, one is to use the APC extension module written by the founder of PHP Rasmuslerdorf, and the other is to use the PECL Extension Module uploadprogress to implement the example I have here to give two separate implementations for reference. More flexible applications are modified to suit their needs.
the APC implementation method for uploading file progress in PHP :
Install APC, refer to the Official document installation, you can use the Pecl module installation method quick and simple, here does not explain the configuration php.ini, set the parameters apc.rfc1867=1, so that APC support the upload progress bar function, in the APC source code documentation, there is a description of the codes example:
- if ($_server[' Request_method ']== ' POST ') {//upload request
- $ status = Apc_fetch (' Upload_ '. $_post[' apc_upload_progress ');
- $status [' Done ']=1;
- Echojson_encode ($status);//output to Ajax calls in user-side pages, related documents please find yourself
- exit;
- }elseif (isset ($_get[' Progress_key ')) {//Read upload progress
- $ status = apc_fetch (' Upload_ '. $_get[' Progress_key ');
- Echojson_encode ($status);
- exit;
- }else{
- //other code, such as upload form etc.
- }
PHP Upload file Progress of the Uploadprogress module implementation method :
Install the module using the PECL module installation method php.ini 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,26jul199705:00:00gmt");
- Header ("last-modified:". Gmdate ("D,dmyh: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)) {
- Echojson_encode ($uploadvalues);
- }else{
- Read progress failed, additional processing logic
- }
- }else{
- Show Upload Form
- }
http://www.bkjia.com/PHPjc/446544.html www.bkjia.com true http://www.bkjia.com/PHPjc/446544.html techarticle PHP is still more commonly used, so I studied the PHP upload file progress, here to take out and share with you, hope to be useful to everyone. PHP is very difficult to implement the upload progress bar is ...