PHP File upload progress bar specific implementation Method _php tutorial

Source: Internet
Author: User
When we write the file upload code, we also need to consider an important implementation function, that is the file upload required progress bar. Now I knowHere are two examples to be implemented separately for reference, more flexible applications to modify according to their own needs.

APC php File Upload progress bar Implementation method:

Install APC, refer to the Official document installation, you can use the Pecl module installation method quick and simple, here does not explain

Configure the php.ini, set the parameter apc.rfc1867=1, enable APC to support the upload progress bar function, in the APC source code document contains the description

code 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:

Implementation of the PHP file upload progress bar for installing the module using the PECL module installation method

PHP.ini inside set uploadprogress.file.filename_template = "/tmp/upd_%s.txt"

code example:

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

These are the two types of PHP files that we introduced to upload progress bar specific methods.


http://www.bkjia.com/PHPjc/446391.html www.bkjia.com true http://www.bkjia.com/PHPjc/446391.html techarticle when we write the file upload code, we also need to consider an important implementation function, that is the file upload required progress bar. At the moment I know I'm here to give you two different implementations ...

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