PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
lwi
Forum Newbie
Posts: 3 Joined: Fri Aug 06, 2004 9:53 am
Post
by lwi » Fri Aug 06, 2004 9:53 am
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
Last edited by
lwi on Fri Aug 06, 2004 2:12 pm, edited 1 time in total.
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Fri Aug 06, 2004 11:27 am
Does the path variable represent the path and the file or just the directory path of your file?
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Fri Aug 06, 2004 11:27 am
I just looked up some code on how I did it. Try this:
Code: Select all
<?php
header ('Content-Length: '.$size. "bytes");
?>
lwi
Forum Newbie
Posts: 3 Joined: Fri Aug 06, 2004 9:53 am
Post
by lwi » Fri Aug 06, 2004 11:53 am
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.
lwi
Forum Newbie
Posts: 3 Joined: Fri Aug 06, 2004 9:53 am
Post
by lwi » Fri Aug 06, 2004 2:37 pm
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):
I'm even more puzzled now..
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Fri Aug 06, 2004 4:16 pm
May be a non-issue, but when I send the content length header, "length" is all lowercase, not "Length".
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Joe
Forum Regular
Posts: 939 Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow
Post
by Joe » Fri Aug 06, 2004 6:27 pm
Have you tried in different browsers?