note 91099 deleted from function.ftp-nb-fget by danbrown
| From: | danbrown@php.net | Date: | Mon, 25 May 2009 22:09:57 +0000 |
| Subject: | note 91099 deleted from function.ftp-nb-fget by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155979@lists.php.net to get a copy of this message | ||
Note Submitter: max at ics dot net dot ua
----
Here is more resource efficient sample:
<?php
// get the size of the remote file
$fs = ftp_size($my_connection, "test");
$fp = fopen('test','w');
// Initate the download
$ret = ftp_nb_fget($my_connection, $fp, "README", FTP_BINARY);
while ($ret == FTP_MOREDATA) {
clearstatcache(); // <- this is important
$dld = ftell($fp);
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);
}
fclose($fp);
?>