views:

28

answers:

2

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.

+1  A: 

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;
}
?>
Fosco
A: 

audio/mpeg for mp3 i found on this website

check it anyway

http://www.w3schools.com/media/media_mimeref.asp

zod