PHP gets upload file progress via APC

Source: Internet
Author: User
Tags add time apc

Business requirements to get the progress of uploading a post file, usually PHP scripts to be executed after the post upload file is completed, so there is no way to get the upload speed directly within the script, not as the execution time, and then the end of the <?php at the beginning of a time and then add time to subtract.

The first way to think of this is through Ajax, before uploading a request to the server to record the current time, and then post the file.
Of course, this is not the solution, only to know the file upload start of the approximate time, and the end time, the progress is not known.

Check it out online:

Http://www.cnblogs.com/yjf512/p/3173457.html
Http://www.laruence.com/2011/10/10/2217.html

There are two ways, one is more than 5.2 APC, and the other is the PHP5.4 session mechanism. Because the session mechanism requires 5.4, so still choose APC Bar, APC ready to be integrated into PHP, this thing is very useful!

PHP Manual Description: http://cn2.php.net/manual/en/apc.configuration.php#ini.apc.rfc1867

APC first to determine the configuration
Apc.rfc1867=on

Then the form:

[HTML]View Plaincopyprint?
  1. <form enctype="Multipart/form-data" action="up4.php" method="POST">
  2. <input type="hidden" name="apc_upload_progress" value="abc"/>
  3. Send This file: <input name= "userfile" type="file" />
  4. <input type="Submit" value= "Send File" />
  5. </form>


Forms note the hidden fields of apc_upload_progress must precede the file field
And then the PHP file that queries the progress.

[PHP]View Plaincopyprint?
    1. <?php
    2. Print_r (Apc_fetch ("UPLOAD_ABC"));

When you upload it, you can see the upload progress by executing the query file.

PS: Add, usually this skill can only be the query upload progress, the role is not small. However, when the sequence of uploading fragmented files in the case, the PHP side to know the shards being uploaded (it is convenient to tell the client what the next piece), then it seems more meaningful.

PHP gets upload file progress via APC

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.