My code:
$conn_id = ftp_connect($ip_address, $port);
$login_result = ftp_login($conn_id, $username, $password);
if ((!$conn_id) || (!$login_result)) {
$p->setProgressBarProgress(0,"Connection error", "red");
}else{
$size_ftp = ftp_size($conn_id, $file_ftp);
$ret = ftp_nb_get($conn_id, $file_locally, $file_ftp, FTP_BINARY);
while ($ret == FTP_MOREDATA) {
$size_locally = ( file_exists($file_locally) ? filesize($file_locally) : "-");
$perc = round(($size_locally/$size_ftp)*100);
$p->setProgressBarProgress($perc, common::formatBytes($size_locally)." of ".common::formatBytes($size_ftp), "orange");
// Continue downloading...
$ret = ftp_nb_continue($conn_id);
}
if ($ret != FTP_FINISHED) {
$p->setProgressBarProgress(100,"Download failed", "red");
}else{
$p->setProgressBarProgress(100,"Download complete", "green");
}
}
该行:
$size_locally = ( file_exists($file_locally) ? filesize($file_locally) : "-");
获取初始文件大小,例如:1460(即 1.43 kb),这就是问题所在......文件大小不会根据下载的内容而改变。如果我刷新 Windows 资源管理器中的文件夹,我可以看到文件大小随着下载量的增加而变化。如果我在循环时回显文件大小,我会看到无尽的:1460 1460 1460 1460 1460 1460
我尝试过冲洗,ob_flush等...不起作用。
在我的脚本的顶部,我有这样一行:
ob_end_clean();
ini_set('output_buffering', '0');
这是刷新进度条所必需的(有效)。
当文件大小不断增加时,如何获取最新的文件大小?