PHP uses APC to realize real-time upload progress bar function _php Skill

Source: Internet
Author: User

PHP does not have real-time upload progress bar function, if you want to have this function we will generally use Ajax to achieve, but PHP provides an APC, it can with PHP configuration implementation upload progress bar function.
The main target is the application on window.
1. The server to support APC expansion, without this extension, download an extended extension requires more than php.5.2.
2. Configure APC configuration, restart Apache
the code is as follows

Extension=php_apc.dll
apc.rfc1867 = On
Apc.max_file_size = 1000M
Upload_max_filesize = 1000M
Post_max_size = 1000M
explain: As for the parameters to match how big, need to see the project needs apc.max_file_size, set up APC support upload file size, request Apc.max_file_size<=upload_max_ FileSize and apc.max_file_size <=post_max_size. You can implement APC support by restarting Apache.
3. Use Phpinfo () in the code to see if the APC extension is installed.
4. Here is the implementation code:
getprogress.php
the code is as follows

<?php 
session_start (); 
if (Isset ($_get[' Progress_key ')) { 
 $status = apc_fetch (' upload_ '. $_get[' Progress_key ']); 
 Echo ($status [']/$status [' Total ']) *100 
} 
? > 
upload.php
php Code
<?php 
 $id = $_get[' id ']; 
? > 
<form enctype= "Multipart/form-data" id= "Upload_form" action= "target.php" method= "POST" > 
< Input type= "hidden" name= "apc_upload_progress" id= "Progress_key" 
 value= "<?php echo $id?>"/> 
< Input type= "file" id= "Test_file" name= "Test_file"/><br/> <input onclick= 
" Window.parent.startProgress (); return true; " 
 Type= "Submit" value= "Upload"/> 

target.php
The code is as follows

<?php 
set_time_limit (); 
if ($_server[' Request_method ']== ' POST ') { 
 move_uploaded_file ($_files["Test_file"] ["Tmp_name"], 
 dirname ($ _server[' Script_filename ']. " /uploadtemp/". $_files["Test_file" ["Name"])//uploadtemp folder in the same directory under this script 
 echo "<p> upload success </p>"; 
> 

index.php
The code is as follows

<?php $id = MD5 (Uniqid (rand (), true); ?>  

The above is to share with you PHP using APC to achieve real-time upload progress bar function method, I hope to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.