如何在 PHP Shell 脚本中显示文件下载进度?

发布于 2024-08-13 16:08:05 字数 105 浏览 2 评论 0原文

我有一个 php shell 脚本,可以下载一个大文件,在下载过程中能够在 shell 中看到下载进度有点奢侈,任何人都知道如何实现这一点(或者至少指出我的方向是正确的!)

谢谢!

I have a php shell script that downloads a large file, it would be a bit of a luxury to be able to see the progress of the download in shell while it's happening, anyone have any idea how this can be achieved (or at least point me in the right direction!)

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我的鱼塘能养鲲 2024-08-20 16:08:05

您可以尝试在下载时轮询已下载文件的文件大小,并将其与您请求的文件的文件大小进行比较。

You could try to poll the filesize of the downloaded file as it's downloading, and compare it with the filesize of the file you requested.

遮了一弯 2024-08-20 16:08:05

这似乎有效(出乎意料!)

echo "wget '$feedURL'\n";
$execute = "wget -O ".$filePath." '$feedURL'\n";
$systemOutput = shell_exec($execute);
$systemOutput = str_replace( "\n", "\n\t", $systemOutput);
echo "\t$systemOutput\n";

This seemed to work (unexpectedly!)

echo "wget '$feedURL'\n";
$execute = "wget -O ".$filePath." '$feedURL'\n";
$systemOutput = shell_exec($execute);
$systemOutput = str_replace( "\n", "\n\t", $systemOutput);
echo "\t$systemOutput\n";
童话里做英雄 2024-08-20 16:08:05

读取文件的标头以获取文件的大小(如果该信息可用)。然后跟踪您已下载的数量,这将为您提供百分比。
您如何执行此操作取决于您使用的库/函数。

Read the header of the file to get the size of the file (if that information is available). Then keep track of how much you have downloaded and that will give you your percentage.
How you might do that depends on what libraries/functions you are using.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文