HTML_Progress
[ class tree: HTML_Progress ] [ index: HTML_Progress ] [ all elements ]

Source for file progressbar.php

Documentation is available at progressbar.php

  1. <?php
  2. @include '../include_path.php';
  3. /**
  4.  * Progress meter is running in indeterminate mode while a file upload operation.
  5.  * This example may work with HTML_Progress 1.1
  6.  * but version 1.2.0 or better allows more easy facilities.
  7.  *
  8.  * @version    $Id: progressbar.php,v 1.2 2004/07/02 17:52:45 farell Exp $
  9.  * @author     Laurent Laville <pear@laurent-laville.org>
  10.  * @package    HTML_Progress
  11.  */
  12.  
  13. require_once 'HTML/Progress.php';
  14.  
  15. function _methodExists($name)
  16. {
  17.     if (substr(PHP_VERSION,0,1'5'{
  18.         $n strtolower($name);
  19.     else {
  20.         $n $name;
  21.     }
  22.     if (in_array($nget_class_methods('HTML_Progress'))) {
  23.         return true;
  24.     }
  25.     return false;
  26. }
  27.  
  28. /*
  29.     User callback called pending progress meter is running, comes with version 1.2.0RC3
  30.  */
  31. function myFunctionHandler($progressValue&$obj)
  32. {
  33.     global $version;
  34.     global $stop;
  35.     $semaphore './uploads/'.$_GET['ID'];
  36.     
  37.     if (file_exists($semaphore)) {
  38.         $stop file_get_contents($semaphore);
  39.         $obj->setValue(100);
  40.         $obj->setIndeterminate(false);
  41.         $obj->display();
  42.         unlink($semaphore);
  43.     }
  44.  
  45.     // sleep a bit ...
  46.     if ($version > 1.1{
  47.         $obj->sleep();
  48.     else {
  49.         for ($i=0; $i<($obj->_anim_speed*1000)$i++}
  50.     }
  51. }
  52.  
  53. /*
  54.     Which version of html_progress: (stable)1.1 or (beta)1.2.0 RC1, RC2 or RC3
  55.  */
  56. $version _methodExists('run'? 1.2 : 1.1;
  57.  
  58. $progress = new HTML_Progress();
  59. $progress->setIncrement(10);
  60. $progress->setAnimSpeed(100);
  61. $progress->setIndeterminate(true);     // progress bar run in indeterminate mode
  62. $progress->setStringPainted(true);     // get space for the string
  63. $progress->setString("");              // but don't paint it
  64. if ($version > 1.1{
  65.     // set a progress handler required at least version 1.2.0RC3
  66.     $progress->setProgressHandler('myFunctionHandler');
  67. }
  68. $ui $progress->getUI();
  69. $ui->setProgressAttributes(array(
  70.     'background-color' => '#e0e0e0'
  71. ));        
  72. $ui->setStringAttributes(array(
  73.     'color'  => '#996',
  74.     'background-color' => '#CCCC99'
  75. ));        
  76. $ui->setCellAttributes(array(
  77.     'active-color' => '#996'
  78. ));
  79. ?>
  80. <html>
  81. <head>
  82. <style type="text/css">
  83. <!--
  84. body {
  85.     background-color: #CCCC99;
  86.     color: #996;
  87.     font-family: Verdana, Arial;
  88. }
  89. <?php echo $progress->getStyle()?>
  90. // -->
  91. </style>
  92. <script type="text/javascript">
  93. <!--
  94. <?php echo $progress->getScript()?>
  95. //-->
  96. </script>
  97. </head>
  98. <body>
  99.  
  100. <?php 
  101. echo $progress->toHtml()
  102.  
  103. if (isset($_GET['ID'])) {
  104.  
  105.     if ($version > 1.1{
  106.     $progress->run();    // run method is born on version 1.2.0RC3
  107.     else {
  108.         // do the same as run() method
  109.         do {
  110.             $progress->display();
  111.             myFunctionHandler($progress->getValue()$progress);
  112.             if ($progress->getPercentComplete(== 1{
  113.                 if ($progress->isIndeterminate()) {
  114.                     $progress->setValue(0);
  115.                 else {
  116.                     break;
  117.                 }
  118.             }
  119.             $progress->incValue();
  120.         while(1);
  121.     }
  122.     if ($stop == 'done'{
  123.         echo '<b>Upload Complete...</b>';
  124.     else {
  125.         echo '<b>File was not uploaded !</b>';
  126.         echo '<br/><font size="1">'.$stop.'</font>';
  127.     }
  128. }    
  129. ?>
  130.  
  131. </body>
  132. </html>

Documentation generated on Mon, 11 Mar 2019 13:52:38 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.