When we write the file upload code, we also need to consider an important realization of the function, that is, the progress of the required file upload. Currently I know PHP file upload progress bar in two ways, one is to use APC extension module written by PHP founder Rasmus Lerdorf to achieve, the other method is to use PECL extension module uploadprogress achieve.
Specific AJAX technology-based PHP parsing PHP restrictions on the specific solution to upload file size PHP batch upload pictures specific way PHP dynamic multi-file upload specific code to share PHP generic file upload class specific analysis I give two were implemented For reference, more flexible application to modify according to their needs.
APC PHP file upload progress bar to achieve:
Install APC, refer to the official document installation, you can use the PECL module installation method is quick and easy, do not explain here
Configure php.ini, set the parameters apc.rfc1867 = 1, so APC support upload progress bar function, APC source documentation
Code example:
if ($ _SERVER [REQUEST_METHOD] == POST) {// Upload request $ status = apc_fetch (upload_. $ _POST [APC_UPLOAD_PROGRESS]); $ status [done] = 1; echo json_encode ($ status); // Output to user The end of the page ajax call, the relevant documents please find their own exit;} elseif (isset ($ _GET [progress_key])) {read the progress of the upload $ status = apc_fetch (upload _. $ _ GET [progress_key]); echo json_encode ( $ status); exit;} else {// Other code like upload form, etc}
uploadprogress module to achieve:
PECL module installation method to install the PHP file upload progress bar implementation
php.ini set uploadprogress.file.filename_template = "/tmp/upd_%s.txt"
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.