Reputation: 2094
hello there okay so this is the deal i have my mp3 files on my server and each one is in its own folder. in that folder is the mp3 and a php file with the following script:
<?php
// We'll be outputting a PDF
header('Content-type: audio/mp3');
// It will be called file.mp3
header('Content-Disposition: attachment; filename="mysong.mp3"');
// The PDF source is in original.mp3
readfile("mysong.mp3");
?>
the problem is that when i click to go that php page the headers are suppose to make it so that it automatically downloads the mp3 file yet when it downloads it downloads a 300KB file but when i go to the actual link for the mp3 file it plays it perfectly in the browser so im guessing something is wrong with the php file giving the headers.
Upvotes: 2
Views: 6754
Reputation: 38506
Try this more complete example taken from http://us.php.net/readfile
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
Upvotes: 8