Php apc module implements Upload progress bar, phpapc module progress bar _ PHP Tutorial

Source: Internet
Author: User
Tags apc apc module
The APC module of PHP implements the upload progress bar and the phpapc module progress bar. The APC module of PHP implements the upload progress bar. the APC module of the phpapc module is named AlternativePHPCache. APC can cache all PHP code. In addition, it provides a php apc module for upload progress and a phpapc module progress bar.

APC module. its full name is Alternative PHP Cache. APC can cache all PHP code and provide certain memory caching functions. however, this function is not perfect. it is reported that frequent use of the write function of APC cache will lead to unexpected errors. if you want to use this function, you can look at several functions related to apc cache, such as apc_fetch and apc_store.
Fortunately, APC has been added since 5.2.APC_UPLOAD_PROGRESSSolved the long-standing progress bar problem. In addition, it caches all the temporary files during the original upload to the memory and saves them to the hard disk automatically when the temporary files reach the set value, effectively improving the memory utilization.
ItsWorking PrincipleIt is a unique ID assigned to each Upload during the upload. when the PHP script receives an upload file, the interpreter automatically checks the hidden field named APC_UPLOAD_PROGRESS in the $ _ POST array, it will become a cache variable, storing information about the upload, so that the script can access the status information of the uploaded file through the upload ID.

 
 

The most important thing is the hidden domain of APC_UPLOAD_PROGRESS. with this script, you can access the status of the currently uploaded File. just add a p to display the upload status.
The following is an Ajax processing script that uses the Jquery framework to transmit messages in json format.

Function getProgress (upid) {var url = "<{$ siteurl}> epadmin/upprocess"; $. getJSON (url, {progress_key: upid}, function (json) {$ ("# progressinner "). width (json. per + "%"); $ ("# upstatus" ).html ('file size: '+ json. total + 'KB' + 'uploaded: '+ json. current + 'KB'); if (json. per <100) {setTimeout (function () {getProgress (upid) ;}, 10) ;}else {$ ("# upstatus" ..html ("video Upload completed, processing data. please wait ...... ") ;}} Function startProgress (upid) {$ (" # progressouter ").css ({display:" block "}); setTimeout (function () {getProgress (upid);}, 100 );}

The next step is to read the PHP code in the upload status. As for the process of uploading files, you can write them by yourself.
// File upload operation function, which can be compiled as needed

Function upflvAction () {if ($ _ SERVER ['request _ method'] = 'post ') {$ subject = trim ($ this-> f-> filter ($ this-> _ request-> getPost ('subobject '))); $ content = trim ($ this-> f-> filter ($ this-> _ request-> getPost ('content'); Zend_Loader :: loadClass ('m M _ flvop'); $ flv = new Custom_FlvOp; $ flv-> uploadFlv ('upfile', $ subject, $ content );}} // This is the function used to read the upload status ~~ Function upprocessAction () {if (isset ($ _ GET ['SS SS _ key']) {$ status = apc_fetch ('upload _'. $ _ GET ['SS SS _ key']); $ json = array ('per '=> $ status ['stream']/$ status ['total'] * 100, & apos; total & apos; = & apos; round ($ status ['total']/1024), & apos; current & apos; = & apos; round ($ status ['current']/1024 ),); require_once ("Zend/Json. php "); echo Zend_Json: encode ($ json );}}

Now, you can deploy your site and check whether the effect is cool?

The above is the key aspect of PHP's APC module's upload progress bar. I hope it will be helpful for you to learn more.

APC module, which is short for Alternative PHP Cache. APC can cache all PHP code. In addition, it provides...

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.