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
ftp_nb_fget
(PHP 4 >= 4.3.0, PHP 5)
ftp_nb_fget — Überträgt den Inhalt einer Datei von dem FTP-Server und speichert sie in eine lokal geöffnete Datei (nicht blockierend)
Beschreibung
ftp_nb_fget() überträgt remote_file von einem FTP-Server und schreibt den Inhalt, in die durch handle identifizierte Datei ab. Der Transfermodus mode muss entweder FTP_ASCII oder FTP_BINARY sein. Der Unterschied zwischen dieser Funktion und ftp_fget() ist, dass diese Funktion die Datei asynchron überträgt, so dass das Programm noch andere Operationen ausführen kann, während die Datei gespeichert wird.
Gibt FTP_FAILED, FTP_FINISHED, oder FTP_MOREDATA zurück.
Siehe auch ftp_nb_get(), ftp_nb_continue(), ftp_fget(), und ftp_get().
ftp_nb_fget
16-Nov-2004 05:53
