note 47439 added to function.ftp-nb-fget

From: Date: Tue, 16 Nov 2004 13:53:34 +0000
Subject: note 47439 added to function.ftp-nb-fget
Groups: php.notes 
Request: Send a blank email to php-notes+get-80594@lists.php.net to get a copy of this message
If you want to monitor the progress of the download, you may use the filesize()-Function. But note: The results of said function are cached, so you'll always get 0 bytes. Call clearstatcache() before calling filesize() to determine the actual size of the downloaded file. This may have performance implications, but if you want to provide the information, there's no way around it. Above sample extended: <?php // get the size of the remote file $fs = ftp_size($my_connection, "test"); // Initate the download $ret = ftp_nb_get($my_connection, "test", "README", FTP_BINARY); while ($ret == FTP_MOREDATA) { clearstatcache(); // <- this is important $dld = filesize($locfile); if ( $dld > 0 ){ // calculate percentage $i = ($dld/$fs)*100; printf("\r\t%d%% downloaded", $i); } // Continue downloading... $ret = ftp_nb_continue ($my_connection); } if ($ret != FTP_FINISHED) { echo "There was an error downloading the file..."; exit(1); } ?> Philip PS: Cancel my previous posting. The code calculated a wrong percentage and I had no explanation for $fs ---- Manual Page -- http://www.php.net/manual/en/function.ftp-nb-fget.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+47439 Delete -- http://master.php.net/manage/user-notes.php?action=delete+47439&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47439&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47439&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47439&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47439&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47439&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+47439&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#80594) next »