APC module, its full name is alternative PHP Cache. APC can cache all PHP code, and it can provide some memory caching capabilities. But this feature is not perfect, and there are reports that if you use the APC cache write feature frequently, it can cause unpredictable errors. If you want to use this feature, look at the APC_FETCH,APC_ A few functions associated with the APC cache, such as the store. The
is happy to start with the 5.2 APC joined Apc_upload_progress , which solves the problem of progress bar that has been bothering us for a long time. And it is the original upload when the temporary files are all cached to memory, when the temporary file reached the set value automatically saved to the hard disk, effectively improve the memory utilization situation.
its principle of Action is to give each upload a unique ID at upload time, when the PHP script receives an upload file, the interpreter automatically checks the $_post array for the name Apc_upload_ PROGRESS's hidden field, which becomes a cache variable, stores information about the upload so that the script can access the status information of the uploaded file via the uploaded ID.
<!– The following is the upload form –> <form enctype= "Multipart/form-data" id= "Upload_form" action= "" method= "POST" > <input type = "hidden" name= "apc_upload_progress" id= "Progress_key" value= "Upid"/> video title: <input type= "text" id= "subject" name = "Subject"/> Video description: <input type= "text" id= "content" name= "content"/> Video tag (comma-separated) <input type= "text" id= "tag "Name=" tags "/> <input type=" file "id=" Upfile "name=" Upfile "/> <input type=" Submit "id=" Filesubmit "value=" Upload "onclick=" startprogress (' upid '); return true; " /> <!– Note: The parameters in Startprogress (' Upid ') are the only upload parameters you assign from PHP –> </form> <!– below for upload progress bar –> <div " Upstatus "style=" width:500px; height:30px; border:1px solid # #ffffde; Color: #796140; > </div <div id= "Progressouter" style= "width:500px"; height:20px; BORDER:3PX solid #de7e00; Display:none; " > <div id= "Progressinner" style= "position:relative; height:20px; Color: #796140; Background-color: #f6d095; width:0%;
"></div> </div>
The most important is that apc_upload_progress hidden domain, with its script to access the current status of uploaded files, plus a display of the status of the Div.
Here's a script that handles Ajax, using the jquery framework and JSON to deliver the message.
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 < MB) {
settimeout (function () {
getprogress (upid);
}, ten);
} else{
$ ("#upstatus"). HTML ("Video upload complete, processing data, please later ...")}
function Startprogress (upid) {
$ ("#progressouter"). CSS ({display: "block"});
settimeout (function () {
getprogress (upid);
}
Then down is to read the upload state of the PHP code, as for the upload file processing can be written in accordance with their usual.
Upload file operation function, you can write 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 to read the upload state ~ ~ function
upprocessaction ()
{
if (isset ($_get[' Progress_key ')) {
$status = Apc_fetch (' Upload_ '. $_get[' Progress_key '));
$json = Array (
' => ' $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, look at the effect is not very cool?
The above is the PHP APC module production upload progress bar key point introduction, hope for everyone's learning to have inspiration, to everyone help.