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

Source for file hbar.php

Documentation is available at hbar.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: hbar.php,v 1.1 2004/06/26 12:22:52 farell Exp $
  9.  * @author     Laurent Laville <pear@laurent-laville.org>
  10.  * @package    HTML_Progress
  11.  */
  12.  
  13. require_once 'HTML/Progress.php';
  14. require_once 'HTML/Progress/observer.php';
  15.  
  16. {
  17.     var $_console;
  18.     
  19.     function logsUpload()
  20.     {
  21.         $isodate date('Y-m-d');
  22.         $this->_console './uploads/http4_' $isodate '.log';
  23.         $this->HTML_Progress_Observer();
  24.     }
  25.  
  26.     function notify($event)
  27.     {
  28.         $semaphore './uploads/'.$_GET['ID'];
  29.  
  30.         if (file_exists($semaphore&& $event['value'< 100{
  31.             $stop file_get_contents($semaphore);
  32.             $date date('H:i:s');
  33.             $ip $_SERVER['REMOTE_ADDR'];
  34.             $msg = "$date - $ip - file upload: $stop";
  35.  
  36.             error_log("$msg \n"3$this->_console);
  37.         }
  38.     }
  39. }
  40.  
  41. function _methodExists($name)
  42. {
  43.     if (substr(PHP_VERSION,0,1'5'{
  44.         $n strtolower($name);
  45.     else {
  46.         $n $name;
  47.     }
  48.     if (in_array($nget_class_methods('HTML_Progress'))) {
  49.         return true;
  50.     }
  51.     return false;
  52. }
  53.  
  54. /*
  55.     User callback called pending progress meter is running, comes with version 1.2.0RC3
  56.  */
  57. function myFunctionHandler($progressValue&$obj)
  58. {
  59.     global $version;
  60.     global $stop;
  61.     $semaphore './uploads/'.$_GET['ID'];
  62.     
  63.     if (file_exists($semaphore)) {
  64.         $stop file_get_contents($semaphore);
  65.         $obj->setValue(100);
  66.         $obj->setIndeterminate(false);
  67.         $obj->display();
  68.         unlink($semaphore);
  69.     }
  70.  
  71.     // sleep a bit ...
  72.     if ($version > 1.1{
  73.         $obj->sleep();
  74.     else {
  75.         for ($i=0; $i<($obj->_anim_speed*1000)$i++}
  76.     }
  77. }
  78.  
  79. /*
  80.     Which version of html_progress: (stable)1.1 or (beta)1.2.0 RC1, RC2 or RC3
  81.  */
  82. $version _methodExists('run'? 1.2 : 1.1;
  83.  
  84. $progress = new HTML_Progress();
  85. $observer = new logsUpload();          // prepare the progress meter to logs all upload operations
  86. $progress->addListener($observer);
  87. $progress->setIncrement(10);
  88. $progress->setAnimSpeed(100);
  89. $progress->setIndeterminate(true);     // progress bar run in indeterminate mode
  90. $progress->setStringPainted(true);     // get space for the string
  91. $progress->setBorderPainted(true);
  92. $progress->setString("");              // but don't paint it
  93. if ($version > 1.1{
  94.     // set a progress handler required at least version 1.2.0RC3
  95.     $progress->setProgressHandler('myFunctionHandler');
  96. }
  97. $ui $progress->getUI();
  98. $ui->setBorderAttributes('width=1 style=inset color=white');
  99. $ui->setCellAttributes(array(
  100.     'active-color' => '#000084',
  101.     'inactive-color' => '#3A6EA5',
  102.     'width' => 25,
  103.     'spacing' => 0,
  104.     'background-image' => 'download.gif'
  105. ));
  106. $ui->setStringAttributes(array(
  107.     'width' => 60,
  108.     'font-size' => 10,
  109.     'background-color' => '#C3C6C3'
  110. ));
  111. ?>
  112. <!DOCTYPE html
  113.     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  114.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  115.  
  116. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  117. <head>
  118. <style type="text/css">
  119. <!--
  120. body {
  121.     background-color: #C3C6C3;
  122.     color: #000000;
  123.     font-family: Verdana, Arial;
  124. }
  125. <?php echo $progress->getStyle()?>
  126. // -->
  127. </style>
  128. <script type="text/javascript">
  129. <!--
  130. <?php echo $progress->getScript()?>
  131. //-->
  132. </script>
  133. </head>
  134. <body>
  135.  
  136. <?php 
  137. echo $progress->toHtml()
  138.  
  139. if (isset($_GET['ID'])) {
  140.  
  141.     if ($version > 1.1{
  142.     $progress->run();    // run method is born on version 1.2.0RC3
  143.     else {
  144.         // do the same as run() method
  145.         do {
  146.             $progress->display();
  147.             myFunctionHandler($progress->getValue()$progress);
  148.             if ($progress->getPercentComplete(== 1{
  149.                 if ($progress->isIndeterminate()) {
  150.                     $progress->setValue(0);
  151.                 else {
  152.                     break;
  153.                 }
  154.             }
  155.             $progress->incValue();
  156.         while(1);
  157.     }
  158.     if ($stop == 'error'{
  159.         echo '<b>File was not uploaded !</b>';
  160.     else {
  161.         echo '<b>Upload Complete...</b>';
  162.     }
  163. }    
  164. ?>
  165.  
  166. </body>
  167. </html>

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