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.