search
Homephp教程php手册PHP利用apc实现上传进度条方法

PHP利用apc实现上传进度条方法

Jun 13, 2016 am 11:27 AM
apcphpuploaduseFunctionCanreal timeaccomplishmethodyesschedule

php本身是不具备可以带有实时上传进度条功能了,如果想有这种功能我们一般会使用ajax来实现,但是php提供了一个apc,他就可以与php配置实现上传进度条哦。

主要针对的是window上的应用。
1.服务器要支持apc扩展,没有此扩展的话,百度一下php_apc.dll ,下载一个扩展扩展要求php.5.2以上。
2.配置apc相关配置,重启apache

 代码如下 复制代码
extension=php_apc.dll  
apc.rfc1867 = on  
apc.max_file_size = 1000M  
upload_max_filesize = 1000M  
post_max_size = 1000M  

 

说明一下:至于参数要配多大,得看项目需要apc.max_file_size,  设置apc所支持上传文件的大小,要求apc.max_file_size 3.在代码里面利用phpinfo();查看apc扩展安装了没有。
4.下面是实现代码:
getprogress.php

 代码如下 复制代码

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="上传"/>  
  

target.php

 代码如下 复制代码
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 "

上传成功

";  
}  
?>  

index.php

 代码如下 复制代码

   $id = md5(uniqid(rand(), true));  
?>  
  

上传进度  
  
  
  
  
  
        src="upload.php?id="   
        style="border: none; height: 100px; width: 400px;" >   
  


  
  

  
  
  
  

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor