Sending large remote file to browser

Hi all,

I’m trying to send a large remote file to the client’s browser.
It works fine, the issue is that the server always sends a “Transfer-Encoding: chunked” header instead of my “Content-length” header, therefore the browser can’t display the progress bar because it doesn’t know the size of the whole file.

I have tried with curl by doing this :
[php]
function receiveResponse($curlHandle,$data)
{
print($data);
return strlen($data);
}

header(“Content-Length: $filesize”);
header(“Content-type: video/flv”);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'receiveResponse');
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'receiveResponse');
curl_exec($ch);
curl_close($ch);

[/php]

I have also tried with sockets by doing this :
[php]
header(“Content-type: video/x-flv”); header("Content-Length: " . $filesize);

$fp = @fsockopen($host, ‘80’, $errno, $errstr, $connTimeout );
fputs($fp, $header);
$pos=false;
while($pos==false) //loop that finds the end of the header and get the size of the file
{
$line = fread($fp, 4096);
$pos = strpos($line, “\r\n\r\n”); //end of header?
if (preg_match(’/Content-Length: (\d+)/’, $line, $matches)) {$filesize = $matches[1];} //gets filesize
}

$apres_header = substr($line, $pos +4); //extract and send to the browser the small piece of the file that
print($apres_header); //was between the end of the header and the beginning of a new chunk

  while($line = fread($fp, 4096)) //sends the reste of the file 
     { 
           print($line); flush(); $count=$count+1;
		   
      } 

[/php]

How can I force PHP to send my content length header and not replace it with its own transfer encoding chunk header??
Thanks for your help!

Sponsor our Newsletter | Privacy Policy | Terms of Service