Page 1 of 1

Tracking mp3 downloads

Posted: Wed Dec 13, 2006 4:53 pm
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?

Posted: Wed Dec 13, 2006 5:09 pm
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?