1

I've got a file called "stream.ogg" which is, well, an internet radio station. If a user tries to download the file, it always appears as "210mb" no matter what OS they try to save it from.

I've got several other files for download, some are .zip, and some are .exe. When someone downloads a file, it says "unknown time remaining" or "unknown file size total" and I was wondering if I could get Apache to relay the total size to the client?

Other servers on the net do have this set up somehow with Apache, for example when downloading a linux distro from any website, it always knows how big the file is. (ex. 19 minutes remaining).

Can anyone help me with this please?

Thanks.

PS: Apache is the latest public release, PHP and scripts are enabled.

Shane Madden
  • 114,520
  • 13
  • 181
  • 251
U4iK_HaZe
  • 633
  • 5
  • 13

1 Answers1

3

You need to send Content-Length header.

If a PHP script initiates the download, you can set the header with:

header('Content-Length: ' . filesize('/path/to/file.ogg'));
xofer
  • 3,072
  • 12
  • 19
  • And filesize is in bytes? – U4iK_HaZe Oct 18 '11 at 22:14
  • Yes, the [Content-Length header](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13) should be in bytes (a.k.a. octets), and [filesize()](http://php.net/filesize) returns the number of bytes. – xofer Oct 18 '11 at 22:18
  • Alright, thanks for the help. How would I do this if I had files for direct download, ie., not from a web browser but instead from a piece of software downloading the files for itself, and display a progress bar? Ah, nevermind. I'll work on that myself another time. Not important. – U4iK_HaZe Oct 18 '11 at 22:38
  • 1
    Have your software read the Content-Length header. :-) – xofer Oct 18 '11 at 23:32
  • Well, it's console based, and it will fetch resources from a server much like MingW setup does. It's not so important. – U4iK_HaZe Oct 19 '11 at 19:35