Source for file observer.php
Documentation is available at observer.php
* Net FTP Observer example to use with HTML_Progress package
* @author Laurent Laville <pear@laurent-laville.org>
* @author Tobias Schlitt <toby@php.net>
* @link http://pear.php.net/package/HTML_Progress
require_once 'Net/FTP.php';
require_once 'Net/FTP/Observer.php';
require_once 'HTML/Progress.php';
* Initializing test variables (required!)
$dest = 'tmp'; // this directory must exists in your ftp server !
$overwrite = true; // overwrite all existing files on the ftp server
'HTML_Progress-1.2.0.tgz',
'php4ever.png' // initializing contents (required!) file(s) must exists
// 1. Defines the FTP/Progress Observer
/* Call the base class constructor. */
Be sure to have an indeterminate progress meter when
@link http://www.php.net/manual/en/function.ftp-nb-put.php
stores a file on the FTP server (non-blocking)
$this->progress->setIndeterminate (true );
if ($this->progress->getPercentComplete () == 1 ) {
// 2. defines the progress meter
$meter = new HTML_Progress ();
$ui->setProgressAttributes (array (
'background-color' => '#e0e0e0'
$ui->setStringAttributes (array (
'background-color' => '#CCCC99'
$ui->setCellAttributes (array (
$meter->setAnimSpeed (200 );
$meter->setIncrement (10 );
$meter->setStringPainted (true ); // get space for the string
$meter->setString (""); // but don't paint it
$meter->setIndeterminate (true ); // progress meter start in indeterminate mode
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>FTP/Progress Observer example</title>
background-color: #CCCC99;
font-family: Verdana, Arial;
<?php echo $meter->getStyle (); ?>
<script type="text/javascript">
<?php echo $meter->getScript (); ?>
@set_time_limit(0 ); // unlimited time operation (removed 30s default restriction)
// 3. connect to the FTP server
$ret = $f->connect ($ftp['host'], $ftp['port']);
if (PEAR ::isError ($ret)) {
printf('connected at <b>%s</b><br />', $ftp['host']);
// 4. login to the FTP server as a well-known user
$ret = $f->login ($ftp['user'], $ftp['pass']);
if (PEAR ::isError ($ret)) {
printf('login as <b>%s</b><br />', $ftp['user']);
// 5. changes directory to final destination for upload operation
if (PEAR ::isError ($ret)) {
// 6. attachs an instance of the FTP/Progress subclass observer
$ok = $f->attach ($observer);
die ('cannot attach a FTP Observer');
// 7. moves files on the FTP server
foreach($files as $file) {
$ret = $f->put ($file, basename($file), $overwrite);
if (PEAR ::isError ($ret)) {
printf('%s <br />', $ret->getMessage ());
continue; // it is just a warning when \$overwrite variable is set to false
// 8. checks if files are really on the FTP server
if (PEAR ::isError ($ret)) {
// 9. says goodbye to the FTP server !
Documentation generated on Mon, 11 Mar 2019 14:11:29 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|