Sending files by Apache and PHP virtual() function

2019-03-31 02:31发布

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.

But is there any way to add continuous download support, with HTTP_RANGE?

I have tried things like this

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); 
} 

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.

I think that there is some way to do it using apache_setenv, but can't find in Google any suggestion about that.

1条回答
Fickle 薄情
2楼-- · 2019-03-31 03:20

Try to use xfilesend module for Apache.

查看更多
登录 后发表回答