The APC method implements PHP to upload multiple file principles Anatomy _php Tutorial

Source: Internet
Author: User
Tags apc configuration php
When uploading multiple files, we may often need a long wait time, and the network and software, and so on, often have time-out and upload failure phenomenon. How to get the file upload progress in real time when uploading multiple files in PHP, and how to avoid PHP and other factors to upload files of any size?

    • Experience Summary: Sample PHP Upload file code
    • Five-minute resolution PHP upload file code Demo
    • Mining php Upload File type principle implementation
    • Three-step FTP implementation of PHP upload file code Analysis
    • Two types of PHP upload file size limit solution
PHP and other languages such as ASP to the upload file processing method, ASP can use Request.BinaryRead streaming read the data submitted by the client. PHP is to store files in a temporary folder, and after the file upload is complete, you can obtain information and manipulate it. If we can get the file name of the temporary file during the uploading process, we can get the upload progress by judging the size of the temporary file, but there seems to be no way to get it. So we can only use the PHP socket extension to build a simple server, post the data to this server, and then use our own mechanism to deal with.

First talk about the process, first use the PHP socket library to establish a temporary HTTP server, at one end of the port listening, and then the IP address and port number to notify the client, the client Upload form submission (temporary server), the temporary server to accept the client request, and read the post data, Analyze and obtain the file information uploaded by the client, save the file on the server, then close the temporary server, release the resources, upload the complete. A bit around, but the idea is still simple.

Later I will publish a class library, tentatively named: Ugia Visual PHP Uploader, so that everyone can be very convenient to call in the program. PHP uploads multiple file effects as follows:

the APC implementation method for uploading multiple files in PHP :

Install APC, refer to the Official document installation, you can use the Pecl module installation method quick and simple, here does not explain the configuration php.ini, set the parameters apc.rfc1867=1, so that APC support the upload progress bar function, in the APC source code documentation, there is a description of the codes example:

 
 
  1. if ($_server[' request_method ' = = ' POST ') {//Upload request
  2. $ Status = Apc_fetch (' Upload_ '. $_post[' apc_upload_progress ');
  3. $status [' done '] = 1;
  4. echo Json_encode ($status); Output to Ajax calls in the user-side page, please find the relevant documents yourself
  5. Exit
  6. } elseif (Isset ($_get[' Progress_key ')) {//Read upload Progress
  7. $ Status = Apc_fetch (' Upload_ '. $_get[' Progress_key ');
  8. echo Json_encode ($status);
  9. Exit
  10. } else {
  11. Other code, such as uploading a form, etc.
  12. }

uploadprogress Module Implementation Method :

 
 
  1. Install the module using the PECL module installation method php.ini inside the setup uploadprogress.file.filename_template = "/tmp/upd_%s.txt" code example:
  2. if ($_server[' Request_method ']== ' POST ') {
  3. if (Is_uploaded_file ($_files[' upfile ' [' tmp_name '])) {
  4. $ Upload_dir = ' your_path/' ;
  5. $ ext = STRRCHR ($_files[' video ' [' Name '], '. ');
  6. $ sessid = $_post[' Upload_identifier '];
  7. $ tmpfile = $upload _dir. $sessid;
  8. $ Sessfile = $upload _dir. $sessid. $ext;
  9. if (Move_uploaded_file ($_files[' upfile ' [' tmp_name '], $tmpfile)) {
  10. Upload successful
  11. } else {
  12. Upload failed
  13. } else {
  14. Upload Error
  15. } elseif (!empty ($_get[' sessid ')) {
  16. Header ("Expires:mon, Jul 1997 05:00:00 GMT");
  17. Header ("last-modified:".) Gmdate ("D, D M Y h:i:s"). "GMT");
  18. Header ("Cache-control:no-store, No-cache, must-revalidate");
  19. header ("Cache-control: post-check=0, pre-check= 0", false);
  20. Header ("Pragma:no-cache");
  21. header ("content-type:text/html; CharSet = UTF -8 ");
  22. $ unique_id = $_get[' sessid '];
  23. $ uploadvalues = Uploadprogress_get_info ($unique _id);
  24. if (Is_array ($uploadvalues)) {
  25. echo Json_encode ($uploadvalues);
  26. } else {
  27. Read progress failed, additional processing logic
  28. }
  29. } else {
  30. Show Upload Form

http://www.bkjia.com/PHPjc/588982.html www.bkjia.com true http://www.bkjia.com/PHPjc/588982.html techarticle when uploading multiple files, we may often need a long wait time, and the network and software, and so on, often have time-out and upload failure phenomenon. How to upload in PHP ...

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