Home  >  Article  >  Backend Development  >  PHP uses apc to implement upload progress bar method_PHP tutorial

PHP uses apc to implement upload progress bar method_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:11:53903browse

PHP itself does not have the function of having a real-time upload progress bar. If we want to have this function, we usually use ajax to implement it, but PHP provides an apc, which can be configured with PHP to implement the upload progress bar.

Mainly targeted at applications on windows.
1. The server must support the apc extension. If there is no such extension, search php_apc.dll on Baidu and download an extension. The extension requires php.5.2 or above.
2. Configure apc related configuration and restart apache

The code is as follows Copy code
extension=php_apc.dll
 代码如下 复制代码
extension=php_apc.dll  
apc.rfc1867 = on  
apc.max_file_size = 1000M  
upload_max_filesize = 1000M  
post_max_size = 1000M  
apc.rfc1867 = on

apc.max_file_size = 1000M

upload_max_filesize = 1000M = 1000M




Explanation: As for the size of the parameters, it depends on the project needs apc.max_file_size, set the upload file supported by apc Size, requires apc.max_file_size <=upload_max_filesize and apc.max_file_size <=post_max_size. Restart apache to achieve apc support.

3. Use phpinfo(); in the code to check whether the apc extension is installed.
代码如下 复制代码

session_start();
if(isset($_GET['progress_key'])) {
$status = apc_fetch('upload_'.$_GET['progress_key']);
echo ($status['current']/$status['total'])*100;
}
?>  
upload.php

PHP Code
$id = $_GET['id'];
?>  

  
id="progress_key" value=""/>  

  
type="submit" value="上传"/>  
  

4. The following is the implementation code:

getprogress.php

The code is as follows Copy code
 代码如下 复制代码
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"]);//UploadTemp文件夹位于此脚本相同目录下
echo "

上传成功

";  
}  
?>  
session_start(); <🎜>if(isset($_GET['progress_key' ])) { <🎜> $status = apc_fetch('upload_'.$_GET['progress_key']); <🎜> echo ($status['current']/$status['total'])*100; < 🎜>} <🎜>?> upload.phpPHP Code $id = $_GET['id']; <🎜>?>
id="progress_key" value=""/> < ;br/> type="submit" value="Upload"/>
target.php
The code is as follows Copy code
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 this script <🎜> echo "

Upload successful

"; } ?>

index.php

 代码如下 复制代码

   $id = md5(uniqid(rand(), true));  
?>  
  
上传进度  
  
  
  
  
  
  


  

  

  
  
  
  


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444615.htmlTechArticlephp本身是不具备可以带有实时上传进度条功能了,如果想有这种功能我们一般会使用ajax来实现,但是php提供了一个apc,他就可以与php配置实...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn