By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

Headers for streaming files

P: n/a
Hi

I know this question is rather HTTP related than PHP, but I did not find an
HTTP group on my news server.

I deliver some files with the following PHP syntax:

header('Content-Description: File Transfer');
header('Content-Type: '.$mimetype);
header('Content-Length: '.filesize($file));
header('Content-Disposition: attachment; filename='.$filename);
readfile($file);

That works well with file types that need to be downloaded to disk. Anyway
if the file is a MP3 file, both IE and Mozilla do the same, they prompt me
to decide if I want to save it to disk, and then download the file entirely
before opening a player.

I sniffed for the differences in headers when a normal link to an mp3 file
is clicked and both tested UAs start streaming and playing immediately:
There is no Content-Disposition header. Removing this header, or just the
"attachment" part of it, results in the expected streaming behaviour, but
the filename is lost, and the script's filename is used instead.

Is it possible to serve the filename without a Content-Disposition header?
Or is there an alternative to the value "attachment", which still allows me
to deliver a filename?

Thanks for a hint
Markus
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Markus Ernst <derernst@no#sp#amgmx.ch> wrote:
There is no Content-Disposition header. Removing this header, or just the
"attachment" part of it, results in the expected streaming behaviour, but
the filename is lost, and the script's filename is used instead.

Is it possible to serve the filename without a Content-Disposition header?
Or is there an alternative to the value "attachment", which still allows me
to deliver a filename?


What about generating URL with the desired filename? There are a couple
of ways to do this (depending on webserver) but easiest is propably with
(apache) MultiViews:
/foo/stream/filename
where stream.php is in the dir foo. The script can retrieve filename
from $_SERVER['PATHINFO'] (IIRC).

The rewrite engine is another easy solution.

--

Daniel Tryba

Jul 17 '05 #2

P: n/a
"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message news:<41***********************@news.easynet.ch>.. .
Hi

I know this question is rather HTTP related than PHP, but I did not find an
HTTP group on my news server.

I deliver some files with the following PHP syntax:

header('Content-Description: File Transfer');
header('Content-Type: '.$mimetype);
header('Content-Length: '.filesize($file));
header('Content-Disposition: attachment; filename='.$filename);
readfile($file);

That works well with file types that need to be downloaded to disk. Anyway
if the file is a MP3 file, both IE and Mozilla do the same, they prompt me
to decide if I want to save it to disk, and then download the file entirely
before opening a player.

I sniffed for the differences in headers when a normal link to an mp3 file
is clicked and both tested UAs start streaming and playing immediately:
There is no Content-Disposition header. Removing this header, or just the
"attachment" part of it, results in the expected streaming behaviour, but
the filename is lost, and the script's filename is used instead.


Try "Content-Disposition: inline; filename=$filename".
Jul 17 '05 #3

P: n/a
Chung Leong wrote:
"Markus Ernst" <derernst@NO#SP#AMgmx.ch> wrote in message
news:<41***********************@news.easynet.ch>.. .
Hi

I know this question is rather HTTP related than PHP, but I did not
find an HTTP group on my news server.

I deliver some files with the following PHP syntax:

header('Content-Description: File Transfer');
header('Content-Type: '.$mimetype);
header('Content-Length: '.filesize($file));
header('Content-Disposition: attachment; filename='.$filename);
readfile($file);

That works well with file types that need to be downloaded to disk.
Anyway if the file is a MP3 file, both IE and Mozilla do the same,
they prompt me to decide if I want to save it to disk, and then
download the file entirely before opening a player.

I sniffed for the differences in headers when a normal link to an
mp3 file is clicked and both tested UAs start streaming and playing
immediately: There is no Content-Disposition header. Removing this
header, or just the "attachment" part of it, results in the expected
streaming behaviour, but the filename is lost, and the script's
filename is used instead.


Try "Content-Disposition: inline; filename=$filename".


Thank you Chung. I tried this, but it did not help as the filename only
seems to have an effect with the attachment setting.

--
Markus
Jul 17 '05 #4

P: n/a
Daniel Tryba wrote:
Markus Ernst <derernst@no#sp#amgmx.ch> wrote:
There is no Content-Disposition header. Removing this header, or
just the "attachment" part of it, results in the expected streaming
behaviour, but the filename is lost, and the script's filename is
used instead.

Is it possible to serve the filename without a Content-Disposition
header? Or is there an alternative to the value "attachment", which
still allows me to deliver a filename?


What about generating URL with the desired filename? There are a
couple of ways to do this (depending on webserver) but easiest is
propably with (apache) MultiViews:
/foo/stream/filename
where stream.php is in the dir foo. The script can retrieve filename
from $_SERVER['PATHINFO'] (IIRC).

The rewrite engine is another easy solution.


Thank you Daniel. I was not aware of MultiViews and will read more on this
interesting possibility. I thought about using the rewrite engine before; I
use it for creating search-engine friendly urls already. Anyway I am not too
familiar with using .htaccess and also don't want to rely on it too much for
non-optional stuff, as the application must be installable on servers with
various configurations.

I think what I will do is actually re-write the application and store the
files with their actual filenames (and validate these on upload), instead of
storing them with custom names and giving the filename back on download, as
I tried. So I won't have to handle the headers at all, as I can simply link
the files.

--
Markus
Jul 17 '05 #5

P: n/a
.oO(Markus Ernst)
I sniffed for the differences in headers when a normal link to an mp3 file
is clicked and both tested UAs start streaming and playing immediately:
There is no Content-Disposition header. Removing this header, or just the
"attachment" part of it, results in the expected streaming behaviour, but
the filename is lost, and the script's filename is used instead.


For streaming MP3s there's another way:

http://www.developingwebs.net/html/mp3.php

Micha
Jul 17 '05 #6

P: n/a
Michael Fesser wrote:

For streaming MP3s there's another way:

http://www.developingwebs.net/html/mp3.php


Thank you for pointing me to this interesting tutorial. This method looks
similar to what you have to do with RealAudio files. Do you know what is the
advantage of using an intermediate text file which points to the audio
source?

--
Markus
Jul 17 '05 #7

P: n/a
.oO(Markus Ernst)
Michael Fesser wrote:

For streaming MP3s there's another way:

http://www.developingwebs.net/html/mp3.php

Thank you for pointing me to this interesting tutorial. This method looks
similar to what you have to do with RealAudio files. Do you know what is the
advantage of using an intermediate text file which points to the audio
source?


The browser only downloads the little text file with the resource
pointer, the download of the media file is handled directly by the
associated application, which will take care of the streaming and maybe
other things (buffering for example).

If you link directly to the media file instead the browser will probably
download it first, before handing over to the player.

Micha
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.