PHP's APC module implements the upload progress bar, PHPAPC module progress bar _php Tutorial

Source: Internet
Author: User
Tags apc apc module

PHP's APC module implements upload progress bar, PHPAPC module progress bar


APC module, its full name is alternative PHP Cache. APC can cache all of the PHP code, and it can provide some memory caching capabilities. But this feature is not perfect, and there are reports of unpredictable errors if you frequently use the APC cache write feature. If you want to use this feature, you can look at the APC_FETCH,APC_ Store and several other functions related to APC cache.
Happily since 5.2, APC has joined the apc_upload_progressto solve the problem of the progress bar that has been bothering you for a long time. And it put the original upload when the temporary files all cached to the memory to change when the temporary file reached the set value automatically saved to the hard disk, effectively improve the memory utilization.
It works by giving each upload a unique ID at upload time, and when the PHP script receives an upload file, the interpreter automatically checks the hidden field named Apc_upload_progress in the $_post array, which becomes the cache variable. Store information about the upload so that the script can access the uploaded file's status information via the uploaded ID.

 
 

The main thing is that Apc_upload_progress's hidden domain, with its script to access the current upload file status, plus a display upload status of the div is good.
Here is the script that deals with Ajax, which uses the jquery framework to deliver the message in JSON.

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 <) {SetTimeout (function () {getprogress (upid);}, 10);} else{$ ("#upstatus"). HTML ("Video upload complete, processing data, please later ...");})} function Startprogress (upid) {$ ("#progressouter"). CSS ({display: "block"}); SetTimeout (function () {getprogress (upid) ;}, 100);}

Again down is the PHP code to read the upload status, as for the processing of the upload file can be written in accordance with the usual own.
Upload file operation function, can be written according to your own needs

function Upflvaction () {if ($_server[' Request_method ']== ' POST ') {$subject = Trim ($this->f->filter ($this->_ Request->getpost (' subject ')); $content = Trim ($this->f->filter ($this->_request->getpost (' content ')); Zend_loader::loadclass (' Custom_flvop '); $flv = new Custom_flvop; $flv->uploadflv (' Upfile ', $subject, $content); }}//This is the function that reads the UPLOAD state ~ ~ Functions Upprocessaction () {if (Isset ($_get[' Progress_key ')) {$status = Apc_fetch (' Upload_ '). $_ get[' Progress_key '); $json = Array (' per ' = = $status [' current ']/$status [' Total ']*100, ' Total ' =>round ($status [' Total ']/1024), ' Current ' =>round ($status [' Current ']/1024),); Require_once ("zend/json.php"); echo Zend_json::encode ($json); } }

OK, now you can deploy it in your own site, see if the effect is cool?

The above is the PHP APC module production upload the key points of the progress bar, I hope that everyone's learning has inspired, helpful to everyone.

http://www.bkjia.com/PHPjc/1065580.html www.bkjia.com true http://www.bkjia.com/PHPjc/1065580.html techarticle PHP's APC module implements the upload progress bar, the PHPAPC Module progress bar APC module, its full name is alternative PHP Cache. APC can cache all of the PHP code, and it can also provide a ...

  • 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.