PHP with APC implementation upload progress bar

Source: Internet
Author: User
Tags apc apc configuration file size php code

PHP with APC implementation upload progress bar, has always thought that PHP is unable to achieve a dynamic function of the progress bar, the original or their own knowledge is not enough, see the APC extension related to some articles, the use of APC expansion to achieve dynamic results. According to find the relevant articles on their own and on this basis made a number of minor changes. Windows for your own server, which is mainly for applications on Windows.
1. The server to support APC expansion, without this extension, Baidu click Php_apc.dll, download an extension of expansion requirements php.5.2 above.
2. Configure APC configuration, restart Apache

PHP Code
    1. Extension=php_apc.dll
    2. apc.rfc1867 = On
    3. Apc.max_file_size = 1000M
    4. Upload_max_filesize = 1000M
    5. Post_max_size = 1000M

Explain: As for the parameters to match how big, need to see the project needs apc.max_file_size, set up APC support upload file size, request Apc.max_file_size <=upload_max_filesize and Apc.max_ File_size <=post_max_size. You can implement APC support by restarting Apache.
3. Use Phpinfo () in the code to see if the APC extension is installed.
4. Here is the implementation code:
getprogress.php

PHP Code
    1. <?php
    2. Session_Start ();
    3. if (Isset ($_get[' Progress_key ')) {
    4. $status = Apc_fetch (' upload_ '. $_get[' Progress_key '));
    5. Echo ($status [']/$status [' Total ']) *100;
    6. }
    7. ?>

upload.php

PHP Code
    1. <?php
    2. $id = $_get[' id '];
    3. ?>
    4. <form enctype= "Multipart/form-data" id= "Upload_form" action= "target.php" method= "POST" >
    5. <input type= "hidden" name= "apc_upload_progress"
    6. Id= "Progress_key" value= "<?php echo $id?>"/>
    7. <input type= "File" id= "Test_file" name= "Test_file"/><br/>
    8. <input onclick= "window.parent.startProgress (); return true; "
    9. Type= "Submit" value= "Upload"/>
    10. </form>


target.php

PHP Code
    1. <?php
    2. Set_time_limit (600);
    3. if ($_server[' Request_method ']== ' POST ') {
    4. Move_uploaded_file ($_files["Test_file"] ["Tmp_name"],
    5. DirName ($_server[' script_filename '). " /uploadtemp/". $_files["Test_file" ["name"]);//uploadtemp folder is located in the same directory as this script
    6. echo "<p> upload success </p>";
    7. }
    8. ?>

index.php

PHP Code
  1. <?php
  2. $id = MD5 (Uniqid (rand (), true);
  3. ?>
  4. <body>
  5. <script src= "Js/jquery-1.4.4.min.js" language= "JavaScript" ></script>
  6. <script language= "JavaScript" >
  7. var pronum=0;
  8. var loop=0;
  9. var Progressresult;
  10. function Sendurl () {
  11. $.ajax ({
  12. Type: ' Get ',
  13. URL: "getprogress.php?progress_key=<?php echo $id;? > ",
  14. Async:true,
  15. Cache:false,
  16. DataType: ' JSON ',
  17. Data: "progress_key=<?php echo $id;? > ",
  18. Success:function (e) {
  19. Progressresult = e;
  20. Pronum=parseint (Progressresult);
  21. document.getElementById ("Progressinner"). Style.width = pronum+ "%";
  22. document.getElementById ("Shownum"). InnerHTML = pronum+ "%";
  23. if (Pronum < 100) {
  24. SetTimeout ("getprogress ()", 100);
  25. }
  26. }
  27. });
  28. }
  29. function getprogress () {
  30. loop++;
  31. Sendurl ();
  32. }
  33. var interval;
  34. function startprogress () {
  35. document.getElementById ("Progressouter"). style.display= "Block";
  36. SetTimeout ("getprogress ()", 100);
  37. }
  38. </script>
  39. <iframe id= "Theframe" name= "Theframe"
  40. Src= "upload.php?id=<?php echo $id;?>"
  41. Style= "Border:none; height:100px; width:400px; ">
  42. </iframe>
  43. <br/><br/>
  44. <div id= "Progressouter" style= "width:500px; height:20px; BORDER:6PX solid red; Display:none; " >
  45. <div id= "Progressinner" style= "position:relative; height:20px; Background-color:purple; width:0%; "></div>
  46. </div>
  47. <div id= ' Shownum ' ></div><br>
  48. <div id= ' showNum2 ' ></div>
  49. </body>


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.