服务器端,获取有关文件发送进度 [英] Server-side, get progress on sending file

查看:196
本文介绍了服务器端,获取有关文件发送进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想要做的是检查我的web服务器已经多少文件发送到客户端,当客户端下载之一。这甚至可能?
阿帕奇是否提供任何模块/扩展,这将有助于我完成我的任务?

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?

我用的Linux发行版,的Apache2和PHP5。问候。

I use a linux distro, apache2 and php5. Regards.

推荐答案

解决了这个问题。

我只需要打开,我要发送到客户端用PHP文件。

I simply open the file with PHP that I want to send to the client.

$fh = fopen($filePath, 'r');

然后我通过写计算文件大小的60%

Then I calculate 60% of the filesize by writing

$fileSize = filesize($filePath);
$sizeFirst = floor(($fileSize / 100) * 60);

现在的$ sizeFirst变量包含的文件的第一个60%的长度,在一个数值。
为了计算剩下的40%我使用的:

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:

$sizeLast = $fileSize - $sizeFirst;

现在我可以写出来的前60%,做我的动作,然后写OUTH剩下的40%。

Now I can write out the first 60%, do my action, and then write outh the rest 40%.

$dataFirst = fread($fh, $sizeFirst);
echo($dataDirst);

// Do my action here.

$dataSecond = fread($fh, $sizeSecond);
echo($dataSecond);
exit();

我需要设置页眉();写出此之前,内容长度,内容类型和内容处置必须以发送一个有效的头和filecontent到客户端进行设置。

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.

希望它可以帮助别人。

这篇关于服务器端,获取有关文件发送进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆