search
Homephp教程php手册用php扩展模块APC实现大文件上传

用php扩展模块APC实现大文件上传

Jun 06, 2016 pm 07:56 PM
apclphpuploadaccomplishExpanddocumentmoduleEnter

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 一。 APC模块的安装与配置 我的环境是Windows,需要去下载php_apc. dll文件,并把php_apc.dll放到php/ext中,并在php.ini中添加以下语句: extension = php_apc.dll apc.rfc1867 = 1 apc.max_file_siz

欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入

    一。 APC模块的安装与配置

    我的环境是Windows,需要去下载php_apc. dll文件,并把php_apc.dll放到php/ext中,并在php.ini中添加以下语句:

    extension = php_apc.dll

    apc.rfc1867 = 1

    apc.max_file_size = 200M

    另外,由于需要上传大文件,所以,在php.ini中,以下选项也需要更改:

    upload_max_filesize = 1000M

    post_max_size = 1000M

    max_execution_time = 600 ;每个PHP页面运行的最大时间值(秒),默认30秒

    max_input_time = 600 ;每个PHP页面接收数据所需的最大时间,默认60秒

    memory_limit = 128M ;每个PHP页面所吃掉的最大内存,默认8M

    二。 获取进度条代码

    getprogress.php

   

    session_start();

    if(isset($_GET['progress_key'])) {

    $status = apc_fetch(‘upload_'.$_GET['progress_key']);

    if($status['total']!=0 && !emptyempty($status['total'])) {

    echo json_encode($status);

    }

    else {

    echo (0);

    }

    }

    ?>

   

    session_start();

    if(isset($_GET['progress_key'])) {

    $status = apc_fetch('upload_'.$_GET['progress_key']);

    if($status['total']!=0 && !empty($status['total'])) {

    echo json_encode($status);

    }

    else {

    echo (0);

    }

    }

    ?>

    这里用到了json,传数据非常方便。

    $status对象是拥有以下字段的数组:

    total: 文件总大小

    current: 到目前为止收到的文件数

    rate: 上传速度(以字节/秒为单位),不过要在上传完成之后才能有。

    filename: 文件名

    name: 变量名

    temp_filename: PHP 保存文件的临时副本的位置

    cancel_upload: 上传已取消(1),还是未取消(0)

    done: 上传已完成(1),还是尚未完成(0)

    这里,我们用json全部传到页面,方便后面利用。

    三。 主文件

    upload.php

   

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

    ?>

   

   

   

Upload Example

   

   

   

   

    action=“target.php” method=“POST”>

   

    id=“progress_key” value=“” />

   

   

    type=“submit” value=“Upload!” />

   

   

    “width: 500px; height: 20px; border: 1px solid black; display:none;”>

   

    “position: relative; height: 20px; background-color: gray; width: 0%; ”>

   

   

   

[1] [2] 

用php扩展模块APC实现大文件上传

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

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),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.