How to Upload a PHP Progress Bar

The PHP language can let you create an upload progress bar that you use to send feedback to the user as a file uploads to your server. You must create an HTML status bar that the PHP language uses to display the status to the user. The code loops until the file finishes uploading to the server.

Instructions

    • 1

      Right-click the PHP file you want to use to display the progress bar and select the editor you want to use. The file opens in the editor where you create the progress bar.

    • 2

      Create the progress bar code in the PHP section of your file. The following code creates the progress bar:

      $url = basename($_SERVER['SCRIPT_FILENAME']);
      if(isset($_GET['progress_key'])) {
      $status = apc_fetch('upload_'.$_GET['progress_key']);
      echo $status['current']/$status['total']*100;
      die;
      }

    • 3

      Scroll down to the HTML section of the page. The following code creates a section of the page where the progress bar displays:

      <div id="progress"></div>

    • 4

      Add the Ajax code that processes the file. The Ajax code calls the PHP code. The Ajax function makes the processing asynchronous, so the user does not have to refresh the page. The following code triggers when the user submits the file to upload it to the server:

      $.get(<?php echo $_GET['up_id']; ?>&randval="+ Math.random(), {
      },
      function(data)
      {
      $('#progress').fadeIn(100);
      $('#progress').html(parseInt(data) +"%");
      }
      )},500);

Related Searches:

References

Comments

Related Ads

Featured