473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Headers for streaming files

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
7 5427
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
"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
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
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
.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
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
.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: A.M-SG | last post by:
Hi, I have a ASP.NET aspx file that needs to pass large images from a network storage to client browser. The requirement is that users cannot have access to the network share. The aspx file...
1
by: adiela | last post by:
hello everyone..i would like to ask something regarding my project.. i've been planning to develop a website using asp code for streaming multimedia features...unfortunatly...i have zero...
5
by: Manuel Alves | last post by:
Hi, Is it possible to store media files (like windows .wmv) on SQL Server 2005 and stream it back to the client via media server (not just download it)? Regards, Manuel Alves
0
by: siddhath | last post by:
Hi all, When I try to open a .pdf file. browser throws a error that pdf file is nt cached. Site has no cache headers applied and SSL is enable. I think this is the reason for that to happen....
0
by: siddharthkhare | last post by:
Hi all, When I try to open a .pdf file. browser throws a error that pdf file is nt cached. Site has no cache headers applied and SSL is enable. I think this is the reason for that to happen....
2
by: Cerebral Believer | last post by:
Hi All, I plan to use streaming audio on my site. I had uploaded some .mp3's as part of a trial, and these streamed very badly so I tried .ram (RealAudio) files instead. The RealAudio files...
8
by: poorna | last post by:
hi all i want to upload the video files to the server.. then i encode all the video files into flv files ... and then i am go to streaming ... in the mean while i create the thumbnail image...
8
by: Amjad | last post by:
Hi i am writing a application where i want to browse video file and copy data into stream and send that stream over network...I have develop P2P windows application where i successfully transfer...
3
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.