title: Retrieve mp3 from mySQL and force download instead of playback in browser
body: <p>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:</p>
  
  <pre><code>header("Content-length:". $audioLength);
  header("Content-type: ". $audioMime );
  
  
  echo $audio;
  </code></pre>
  
  <p>Where the $audioLength and $audioMime are stored with the file in the database and $audio is the actual data.</p>
  
  <p>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:</p>
  
  <pre><code>header("Content-type: attachment/octet-stream");
  header("Content-disposition: attachment; filename=" . $fileName);
  
  echo $audio;
  </code></pre>
  
  <p>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...</p>
  
  <p>M</p>
  
  <p>OK - 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.</p>
  
  <p>So, for any people out there with this question - this is what works:</p>
  
  <pre><code>header('Content-Type: '.$audioMime);
  header("Content-disposition: attachment; filename=" . $fileName);
  
  echo $audio;
  </code></pre>
  
  <p>Ta-da!</p>
  
  <p>Go ahead, laugh at me and give me the idiot of the day badge. I deserve it.</p>
  
  <p>M</p>