Tracking mp3 downloads

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

Post Reply
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Tracking mp3 downloads

Post by andym01480 »

I've written a script that retrieves details about mp3's from a database and outputs them as a table showing relevant info, a link to play it and how many times it downloads.

The link to play it updates the database and then outputs the mp3 - I want people to open or save it, so the code for that I used is...

Code: Select all

header('Content-type: audio/mpeg');
header("Content-Disposition: attachment; filename='$filename'");
readfile("Location:http://www.thebridgechurch.co.uk/sermons/$filename");
where $filename is the retrieved filename - that is tested.

What happens is that only 225-243bytes are output rather 9MB!

If I use just

Code: Select all

header("Location:http://www.thebridgechurch.co.uk/sermons/$filename");
it plays the mp3 straight away. http://www.thebridgechurch.co.uk/index.php?pageid=14

Why does readfile truncate themp3? And how can i get it to work so the file can be opened or saved?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The string you have given readfile() is designed for a header based redirection.

The files appear to be local to your server, so why readfile() a remote page?
Post Reply