Page 1 of 1

Content-Length header not working!

Posted: Fri Aug 06, 2004 9:53 am
by lwi
Hi,

I have a small problem with a download script I have made. Here is the code:

Code: Select all

(snipped authentication / anti-leech code)
$size = filesize($path);
header("Pragma: ");
header("Cache-Control: ");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename="$fileName"");
header("Content-Length: ".$size);

@readfile($path);
die();
The file is downloaded properly, without errors or corruption, but the size of the file is always unknown to the browser, even though I specify it with the Content-Length header. I really don't know why.

Can anybody help?

Thanks in advance,

Lwi

Posted: Fri Aug 06, 2004 11:27 am
by hawleyjr
Does the path variable represent the path and the file or just the directory path of your file?

Posted: Fri Aug 06, 2004 11:27 am
by hawleyjr
I just looked up some code on how I did it. Try this:

Code: Select all

<?php
header ('Content-Length: '.$size. "bytes");
?>

Posted: Fri Aug 06, 2004 11:53 am
by lwi
the $path variable represents both the path and the file name.

In your example there is no space between the size and the word 'bytes'... i assum it's a slight mistake. Either way, I tried both ways:

Code: Select all

<?php
header ('Content-Length: '.$size. "bytes");
?>
and

Code: Select all

<?php
header ('Content-Length: '.$size. " bytes");  // with space before 'bytes'.
?>
None of it seems to work. :(

Posted: Fri Aug 06, 2004 2:37 pm
by lwi
Ok... I downloaded this very useful little gizmo: http://www.blunck.info/iehttpheaders.html. It allows you to view the HTTP headers sent to the browser.

It showed me that the content lenght header is actually sent to the browser, which I find odd.

Here are the headers:
HTTP/1.1 200 OK
Date: Fri, 06 Aug 2004 19:26:10 GMT
Server: Apache/2.0.48 (Unix) mod_ssl/2.0.48 OpenSSL/0.9.7c DAV/2 PHP/4.3.4
X-Powered-By: PHP/4.3.4
Set-Cookie: CerberusPublicGUI=33542c26f030fba2cc41cb22333283aa; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control:
Pragma:
Content-Length: 5310955
Content-Disposition: attachment; filename=AlgolithAE60Setup1.9.zip
Connection: close
Vary: User-Agent
Content-Type: application/octet-stream
But the file size is still unknown (screen shot from Opera):
Image

I'm even more puzzled now..

Posted: Fri Aug 06, 2004 4:16 pm
by pickle
May be a non-issue, but when I send the content length header, "length" is all lowercase, not "Length".

Posted: Fri Aug 06, 2004 6:27 pm
by Joe
Have you tried in different browsers?