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

Source for file shockwaveflash.php

Documentation is available at shockwaveflash.php

  1. <?php
  2. @include '../include_path.php';
  3. /**
  4.  * An example of Listener usage with HTTP_Request and HTML_Progress.
  5.  *
  6.  * Credit: Alexey Borzov <avb@php.net>
  7.  *         for his download-progress.php pattern in HTTP_Request package
  8.  * 
  9.  * @version    $Id: shockwaveflash.php,v 1.1 2004/06/27 14:03:50 farell Exp $
  10.  * @author     Laurent Laville <pear@laurent-laville.org>
  11.  * @package    HTML_Progress
  12.  */
  13.  
  14. require_once 'HTTP/Request.php';
  15. require_once 'HTTP/Request/Listener.php';
  16. require_once 'HTML/Progress.php';
  17.  
  18. class HTTP_Request_DownloadListener extends HTTP_Request_Listener
  19. {
  20.    /**
  21.     * Handle for the target file
  22.     * @var int 
  23.     */
  24.     var $_fp;
  25.  
  26.    /**
  27.     * ProgressBar intance used to display the indicator
  28.     * @var object 
  29.     */
  30.     var $_bar;
  31.  
  32.    /**
  33.     * Name of the target file
  34.     * @var string 
  35.     */
  36.     var $_target;
  37.  
  38.    /**
  39.     * Number of bytes received so far
  40.     * @var int 
  41.     */
  42.     var $_size = 0;
  43.  
  44.     function HTTP_Request_DownloadListener()
  45.     {
  46.         $this->HTTP_Request_Listener();
  47.     }
  48.  
  49.    /**
  50.     * Opens the target file
  51.     * @param string Target file name
  52.     * @throws PEAR_Error
  53.     */
  54.     function setTarget($target)
  55.     {
  56.         $this->_target $target;
  57.         $this->_fp @fopen($target'wb');
  58.         if (!$this->_fp{
  59.             PEAR::raiseError("Cannot open '{$target}'");
  60.         }
  61.     }
  62.  
  63.     function update(&$subject$event$data = null)
  64.     {
  65.         switch ($event{
  66.             case 'sentRequest'
  67.                 $this->_target basename($subject->_url->path);
  68.                 break;
  69.  
  70.             case 'gotHeaders':
  71.                 if (isset($data['content-disposition']&&
  72.                     preg_match('/filename="([^"]+)"/'$data['content-disposition']$matches)) {
  73.  
  74.                     $this->setTarget(basename($matches[1]));
  75.                 else {
  76.                     $this->setTarget($this->_target);
  77.                 }
  78.                 $this->_bar =new HTML_Progress();
  79.                 $this->_bar->setAnimSpeed(10);
  80.                 $inc = isset($data['content-length'])round($data['content-length'/ 100: 1;
  81.                 $this->_bar->setIncrement(intval($inc));
  82.                 echo '<style type="text/css">'.$this->_bar->getStyle().'</style>';
  83.                 echo '<script type="text/javascript">'.$this->_bar->getScript().'</script>';
  84.                 echo $this->_bar->toHtml();
  85.                 $this->_size = 0;
  86.                 break;
  87.  
  88.             case 'tick':
  89.                 $this->_size += strlen($data);
  90.                 $this->_bar->display();
  91.                 $val round($this->_size $this->_bar->getIncrement());
  92.                 $this->_bar->setValue(intval($val));
  93.                 fwrite($this->_fp$data);
  94.                 break;
  95.  
  96.             case 'gotBody':
  97.                 fclose($this->_fp);
  98.                 break;
  99.  
  100.             default:
  101.                 PEAR::raiseError("Unhandled event '{$event}'");
  102.         // switch
  103.     }
  104. }
  105.  
  106. $url 'http://pear.laurent-laville.org/HTML_Progress/examples/viewlet/sw4p.swf';
  107.  
  108. $req =new HTTP_Request($url);
  109.  
  110. $download =new HTTP_Request_DownloadListener();
  111. $req->attach($download);
  112. $req->sendRequest(false);
  113.  
  114.  
  115. $href 'http://'.$_SERVER['SERVER_NAME']dirname($_SERVER['PHP_SELF']'/sw4p.html';
  116. $go '<script type="text/javascript">window.location.href="'.$href.'";</script>';
  117. echo $go;
  118. ?>

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