How to output an MP3 file?
| From: | Brian Dunning | Date: | Wed, 15 Nov 2006 18:01:32 +0000 |
| Subject: | How to output an MP3 file? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-244689@lists.php.net to get a copy of this message | ||
I'm trying to route all my MP3 requests through a brief PHP script to log the downloads to a database, and then I want to output the MP3 exactly as if the browser had requested it normally. So far I haven't found headers that will serve it normally; it either wants to download it as an attachment or an application. I want the browsers to treat it however they normally treat MP3's, usually playing in the browser window. Here's what I'm doing:
(my MP3 files are all named podcast-xxxx.mp3) where $id is the xxx:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=podcast-'.$id.'.mp3');
$size = filesize('audio/podcast-'.$id.'.mp3');
header('Content-Length: '.$size);
readfile('audio/podcast-'.$id.'.mp3');
What should I change?
- Brian