PHP uses APC module to implement large file upload progress bar method, _php tutorial

Source: Internet
Author: User
Tags apc apc module file upload progress bar

PHP uses the APC module to implement a large file upload progress bar method,


PHP large files with the progress of the upload, has been a problem for PHP programmers very vexed. Search Baidu, Google, the general do with the progress of the upload method is: flash+php,socket,apc+php, and so on, I introduced the APC +php+ajax production with the progress of the upload , and paste out the source code, I hope it is useful to everyone.
Alternative PHP cache (APC) is a free, publicly available, optimized code cache for PHP. It is used to provide free, open and robust architecture to cache and optimize PHP's intermediate code.

When using APC, the installation of the APC module must be used first.
First step: Download Php_apc.dll

Step two: Let PHP.ini support the APC expansion module.
Put Php_apc.dll in your ext directory and open php.ini to join:
Extension=php_apc.dll
apc.rfc1867 = On
Apc.max_file_size = 100M
Upload_max_filesize = 100M
Post_max_size = 100M
The above parameters can be defined by themselves

Step three: Check if PHP APC is supported

if (function_exists (' Apc_fetch ')) {echo ' It surpport APC model! ';} else {echo "It ' s not support APC model!";}?>

Below to get to the chase:
principle: through the APC module, the upload progress is read from the cache with Ajas. See:
index.php

<?php $unid =uniqid ("");//To determine the only Peugeot, the implementation of multiple people at the same time upload?> upload the software you are uploading the server, please wait patiently when uploading ...

Upload success! The file size is:

The file download address is:

softupload.php

<?php $id = $_get[' id '];? > 
 
  

target.php

<?php//header (' content-type:text/html;charset=gb2312 ');d efine (' Softdir ', "./upload/"); Post-upload path define (' Httpsoftdir ', "http://www.mysite.com/"); Server path//Determine if the upload software suffix name allows function issoftext ($extension) {$ext = array (' exe ', ' rar ', ' zip ', ' gz '); return In_array ($ extension, $ext)? True:false;} if ($_server[' Request_method ']== ' POST ') {$errors [' 0 '] = true; $errors [' 1 '] = ' Please select the uploaded software picture '; $errors [' 2 '] = ' upload software image failed '; $ errors[' 3 '] = ' failed to upload software image '; $daytime = date (' y-m-d-h-m-s '); $timename =str_replace ("-", "", $daytime); Get date time of day//check if the software is properly uploaded if (!is_uploaded_file ($_files[' softfile '] [' tmp_name ']) {echo ""; Exit } $extension = PathInfo ($_files[' softfile ' [' name '], pathinfo_extension); $filename = $timename. " _ ". $_files[' softfile ' [' name ']; $tmpsize =$_files[' softfile ' [' Size ']; $msize =round ($tmpsize/1048576, 2). " M "; $ksize =round ($tmpsize/1024, 2). "K"; $filesize = $tmpsize >1048576? $msize: $ksize; Check the Software file format if (!issoftext ($extension)) {echo ""; Exit }//Mobile software if (!move_uploaded_file ($_files[' softfile ')[' Tmp_name '], Softdir. $filename)) {echo ""; Exit    }else{echo "uploaded successfully! The file size is:
"; echo "File download address is:"; }} Elseecho "Please do not enter the address directly!" ";? >

getprogress.php

<?php//Upload Ajas Get Progress page session_start (); if (Isset ($_get[' Progress_key ')) {$status = Apc_fetch (' upload_ '. $_get[') Progress_key ']); Echo ($status [' Current ']/$status [' Total ']) *100;} Echo ' apc_file= '. Apc_file;? >

This article for you to provide a PHP production with progress upload file ideas, there may be some lack of place, I hope you can supplement, or is combined with the small series before the article to learn, I hope that everyone's learning has helped.

http://www.bkjia.com/PHPjc/1066505.html www.bkjia.com true http://www.bkjia.com/PHPjc/1066505.html techarticle PHP using the APC module implementation of large file upload progress bar method, PHP large files with progress upload, has been a problem for PHP programmers very vexed. Search Baidu, Google, generally do with ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.