PHP uses apc to implement the upload progress bar method. Php itself does not have the real-time Upload progress bar function. if you want this function, we generally use ajax. However, php provides an apc, php itself does not have the real-time Upload progress bar function. if you want this function, we generally use ajax, but php provides an apc, you can configure the upload progress bar with php.
It mainly targets applications on Windows.
1. the server must support apc extension. if this extension is not available, Baidu php_apc.dll should be used to download an extension that requires php.5.2 or later.
2. configure apc and restart apache.
| The code is as follows: |
|
Extension = php_apc.dll
Apc. rfc1867 = on
Apc. max_file_size = 1000 M
Upload_max_filesize = 1000 M
Post_max_size = 1000 M
|
Note: the size of parameters depends on the project's apc. max_file_size: specifies the size of the files that can be uploaded by apc. apc is required. max_file_size <= upload_max_filesize and apc. max_file_size <= post_max_size. restart apache to support apc.
3. use phpinfo () in the code to check whether the apc extension is installed.
4. The following is the implementation code:
Getprogress. php
| The code is as follows: |
|
|
Session_start ();
If (isset ($ _ GET ['progress _ key']) {
$ Status = apc_fetch ('upload _ '. $ _ GET ['SS SS _ key']);
Echo ($ status ['current']/$ status ['total']) * 100;
}
?>
Upload. php
PHP Code $ Id = $ _ GET ['id'];
?>
|
Target. php
| The code is as follows: |
|
Set_time_limit (600 );
If ($ _ SERVER ['request _ method'] = 'post '){
Move_uploaded_file ($ _ FILES ["test_file"] ["tmp_name"],
Dirname ($ _ SERVER ['script _ filename']). "/UploadTemp /". $ _ FILES ["test_file"] ["name"]); // The UploadTemp folder is located in the same directory as the script.
Echo"
Uploaded ";
}
?>
|
Index. php
| The code is as follows: |
|
|
$ Id = md5 (uniqid (rand (), true ));
?>
Upload progress
|