Php uses APC to implement the real-time Upload progress bar function _ PHP

Source: Internet
Author: User
This article describes how to use APC to implement the real-time Upload progress bar function in php. php does not provide the real-time Upload progress bar function, but php provides an apc, it can be configured with php to implement the upload progress bar. if you are interested, you can refer to the fact that php does not have the real-time Upload progress bar function. if you want this function, we generally use ajax to implement it, however, php provides an apc, which can be configured with php to implement the upload progress bar function.
It mainly targets applications on Windows.
1. the server must support apc extension. if this extension is not available, download php.5.2 or above for an extension.
2. configure apc and restart apache.
The code is as follows:

Extension = php_apc.dll
Apc. rfc1867 = on
Apc. max_file_size = 1000 M
Upload_max_filesize = 1000 M
Post_max_size = 1000 M
Note: the size of the parameters depends on the apc. max_file_size required for the project and the size of the files supported by apc.Apc. max_file_size <= upload_max_filesizeAndApc. max_file_size <= post_max_size.Restart apache to support apc.
3. use phpinfo () in the code to check whether the apc extension is installed.
4. The following is the implementation code:
Getprogress. php
The code is as follows:

<?php session_start(); if(isset($_GET['progress_key'])) {  $status = apc_fetch('upload_'.$_GET['progress_key']);  echo ($status['current']/$status['total'])*100; } ?> upload.phpPHP Code<?php  $id = $_GET['id']; ?>  

Target. php
The code is as follows:

<? Php set_time_limit (600); if ($ _ SERVER ['request _ method'] = 'post ') {move_uploaded_file ($ _ FILES ["test_file"] ["tmp_name"], dirname ($ _ SERVER ['script _ FILENAME ']). "/UploadTemp /". $ _ FILES ["test_file"] ["name"]); // The UploadTemp folder is located in echo under the same directory of the script"

Uploaded

";}?>

Index. php
The code is as follows:

<? Php $ id = md5 (uniqid (rand (), true);?> Upload progress  

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.