通过具有 HTTP_RANGE 支持的 Apache 和 PHP virtual() 函数发送文件 [英] Sending files by Apache and PHP virtual() function with HTTP_RANGE support
问题描述
我正在使用 PHP 函数 virtual() 通过 Apache 2.2 发送文件(它的运行速度比
I'm using PHP function virtual() for sending files by Apache 2.2 (it works faster than readfile()) and I can check user access permissions.
但是有没有办法通过 HTTP_RANGE 添加持续下载支持?
But is there any way to add continuous download support, with HTTP_RANGE?
我尝试过这样的事情
if(isset($_SERVER['HTTP_RANGE'])) {
list($a, $range)=explode("=",$_SERVER['HTTP_RANGE']);
str_replace($range, "-", $range);
$size2=$size-1;
$new_length=$size-$range;
header("HTTP/1.1 206 Partial Content");
header("Content-Length: $new_length");
header("Content-Range: bytes $range$size2/$size");
apache_setenv('HTTP_RANGE', $_SERVER['HTTP_RANGE']);
} else {
$size2=$size-1;
header("Content-Range: bytes 0-$size2/$size");
header("Content-Length: ".$size);
}
所以 web-client 被下载了文件,就像 HTTP_RANGE 工作一样,但实际上 Apache 总是发送相同的文件范围,例如:如果客户端请求 4000-6000 字节,Apache 发送 0-2000 等等,所以文件被破坏了.
So web-client was downloaded files like if HTTP_RANGE works, but in real Apache just sends always the same file-ranges like: if client ask 4000-6000 bytes, Apache sends 0-2000 and etc, so files was broken.
我认为使用 apache_setenv 有一些方法可以做到这一点,但在 Google 中找不到任何关于此的建议.
I think that there is some way to do it using apache_setenv, but can't find in Google any suggestion about that.
推荐答案
尝试使用 Apache 的 xfilesend 模块.
Try to use xfilesend module for Apache.
这篇关于通过具有 HTTP_RANGE 支持的 Apache 和 PHP virtual() 函数发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!