Source for file download-progress.php
Documentation is available at download-progress.php
* An example of Listener usage with HTTP_Request. This downloads and saves
* the file displaying the progress bar in the process.
* 1) The file should be run in console, not in browser;
* 2) You should turn output buffering OFF for this to work properly.
* $Id: download-progress.php,v 1.1 2003/10/27 10:48:49 avb Exp $
require_once 'HTTP/Request.php';
require_once 'HTTP/Request/Listener.php';
require_once 'Console/ProgressBar.php';
PEAR ::setErrorHandling (PEAR_ERROR_DIE );
* Handle for the target file
* Console_ProgressBar intance used to display the indicator
* Name of the target file
* Number of bytes received so far
* @param string Target file name
$this->_target = $target;
$this->_fp = @fopen($target, 'wb');
PEAR ::raiseError (" Cannot open '{$target}'" );
function update(&$subject, $event, $data = null )
$this->_target = basename($subject->_url ->path );
if (isset ($data['content-disposition']) &&
preg_match('/filename="([^"]+)"/', $data['content-disposition'], $matches)) {
$this->_bar = & new Console_ProgressBar (
'* ' . $this->_target . ' %fraction% KB [%bar%] %percent%', '=>', '-',
79 , (isset ($data['content-length'])? round($data['content-length'] / 1024 ): 100 )
$this->_size += strlen($data);
$this->_bar->update (round($this->_size / 1024 ));
PEAR ::raiseError (" Unhandled event '{$event}'" );
// Try using any other package if you like, but choose the bigger ones
// to be able to see the progress bar
$url = 'http://pear.php.net/get/HTML_QuickForm-stable';
$req = & new HTTP_Request ($url);
$req->sendRequest (false );
Documentation generated on Mon, 11 Mar 2019 14:10:28 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|