Retrieve mp3 from mySQL and force download instead of playback in browser

noudreurtt

New Member
I have a site with audio files in a mySQL database, all of which are available for playback. That works fine by using the headers:\[code\]header("Content-length:". $audioLength);header("Content-type: ". $audioMime );echo $audio;\[/code\]Where the $audioLength and $audioMime are stored with the file in the database and $audio is the actual data.I now want to add download links for some of the larger files so it would be very obvious to users who don't know how to download an mp3 from a page that they are welcome to do so and put the music on their devices and share them any other way they like. My PHP is the same except I replaced the headers with:\[code\]header("Content-type: attachment/octet-stream");header("Content-disposition: attachment; filename=" . $fileName);echo $audio;\[/code\]This still causes Safari and Firefox to play the audio, just in a new window. How do I force a download dialog box? I assume most other browsers out there would play the file as well, so I haven't tested those yet...MOK - I'm a blasting idiot!!! I created the PHP file that would download instead of play back from the file that plays back. And I FORGOT TO CHANGE THE REFERENCE TO THE NEW PHP FILE IN THE URL to the files I was retrieving. Brilliant. I had it the first try, it just wasn't working because I was calling the wrong FILE.So, for any people out there with this question - this is what works:\[code\]header('Content-Type: '.$audioMime);header("Content-disposition: attachment; filename=" . $fileName);echo $audio;\[/code\]Ta-da!Go ahead, laugh at me and give me the idiot of the day badge. I deserve it.M
 
Back
Top