服务器端,获取发送文件的进度
基本上,我想做的是在客户端下载文件时检查我的网络服务器已向客户端发送了多少文件。这可能吗? apache 是否提供任何可以帮助我完成任务的模块/扩展?
我使用 Linux 发行版、apache2 和 php5。问候。
Basically, what I want to do is to check how much of a file my webserver has sent to a client, when the client is downloading one. Is this even possible?
Does apache provide any module/extension that would help me accomplish my task?
I use a linux distro, apache2 and php5. Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果文件具有正确的“内容长度”标头设置,浏览器将提供此功能。为什么要在页面中实现此功能?
Browser provides this functionality if file has correct "Content-length" header set. Why do you want to implement this in your page?
解决了。
我只需使用 PHP 打开要发送给客户端的文件。
计算文件大小的 60%
然后,我通过写入Now $sizeFirst 变量包含文件前 60% 的长度(以数值形式)来 。
为了计算剩余的 40%,我使用:
现在我可以写出前 60%,执行我的操作,然后写出剩余的 40%。
我需要设置 header();在写出此内容之前,必须设置 Content-length、Content-type 和 Content-Disposition,以便向客户端发送有效的标头和文件内容。
希望它能帮助某人。
Solved it.
I simply open the file with PHP that I want to send to the client.
Then I calculate 60% of the filesize by writing
Now the $sizeFirst variable contains the length of the first 60% of the file, in a numeric value.
To calculate the rest 40% I use:
Now I can write out the first 60%, do my action, and then write outh the rest 40%.
I need to set the header(); before writing out this, the Content-length, Content-type and Content-Disposition must be set in order to send a valid header and filecontent to the client.
Hope it helps someone.