Getting You Online, Found and Connected

Video Tutorial: How To Force Download an MP3 File Instead of Streaming

Show me the video

A word of warning for the reader, this post will get very techie, I wanted to force download an MP3 file, instead of streaming, the solution requires good knowledge of WordPress, Servers and computer coding. I do explain every step as clearly as possible, but it may still be too much for the average person.

To clearly demonstrate the problem, here are two image links. The one on the left (#1) uses the standard add link process, the one on the right (#2) uses custom code to force the download of the MP3. The preference is to download the file, not play in the browser. Click on both to see what I mean.

1. downloadmp3      2. downloadmp3

Thanks to Eye For Video from for providing the solution (used in the image to the above right).

A video walking through the process is below.

Here is the code to be used

$file = $_GET['file'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header ("Content-Length: ".filesize($file));

Save this code in a file called direct_download.php and save it in the same folder as the MP3 file on your server.

Trying to manage too many passwords? You need LastPass.

Use the following code on your website to call up this file

<a href="direct_download.php?file=filename.mp3">Download the mp3</a>

As I wanted to use an image instead of a text link, I used the following code

<a href="../wp-content/uploads/Podcasts/direct_download.php?file=3RPPTue28May2013YoungDigitalGroup.mp3">
<img alt="downloadmp3" src="" 
width="158" height="35" /></a>

This video is the process explaining how I created and saved these files to make it all work



  • akhil

    hi, tried using the procedure and it worked partially. could download the file but wrongly named as “direct_download.php” instead of the name and extension as mp3. what am i doing wrong? please help. example at following url:

    • John Young

      Make sure the php file only contains the code noted in the post and save it in the save directory as the mp3

      • akhil

        the file is in the same directory as the mp3 that is why it can download. here is the code:

        not a syllable less or more.
        still some issue with naming the file and extension as mentioned in original comment. any help is appreciated. _/_

        • John Young

          Hi Akil, the code didn’t appear on the comment. can you email me at so I can see the code used in the php file.

  • akhil

    Just wish to say a big ThankYou for the support John Young!
    The file you sent through email after corrections is working perfectly. Please allow me to say that it is supportive people like you that make this world a better place. Thanks again for the time and effort.

    • John Young

      Thanks for the kind words Akhil.

  • gQdownloads

    God bless you! it works for me. thanks

  • quinjoyie

    this is not working in iphone and ipad.. how do you work it on iphone and ipad?

  • TrinityGroen2

    Timely analysis . I loved the insight , Does anyone know if my company can find a sample IRS 706 copy to use ?


      Greetings TrinityGroen2, my assistant edited a template IRS 706 form copy at this site

  • Darius Friedel

    DO NOT PLACE THE direct_download.php FILE ON YOUR SERVERS! This file allows anyone to download any file on your server that the web server process owner has access to. Look before you leap people!