Wednesday, June 23, 2010

Embed music with dowload.php file

Scenario: you would like to embed a music file (.mp3 in our example) into your website and also want to make sure that when someone clicks the download link the usual open / save as window opens instead of the browser trying to open the file directly with whatever plugin already installed.

My solution: we'll have to break this down into two parts: one will be the embed script and the other one will be the download link.

Step 1 Embed music with IE support

Sometimes a simple embed music script would not be enough as Internet Explorer has its own way to understand it, therefore the script I'm going to provide you with is one that takes this into account too. I used a not too fancy but very descriptive article simply called Embedding Audio

note: you may replace with your domain name and music/01_mymusic.mp3 with the path to and file name of your .mp3 file on your hosting server:

(click in the box to highlight the code for copy)

Step 2 Download link with download.php file

You'll see an example of a simple but effective way to "call" the little open/save as window when clicking a download link. The forum thread that helped me is called download pdf hyperlink (scroll all the way to the bottom to get the clean version of the code). All I needed to do here is to replace the .pdf with .mp3 and place the download.php file into the folder where my .mp3 files were located on the hosting server (using the same path we refer to in above code):

(click in the box to highlight the code for copy)

No comments:

Post a comment

Dear legitimate commenters, please post your comments below. I'd be happy to receive your feedback; helps me a lot improving, or getting reassurance that I'm doing something really great here.

IMPORTANT! A note to commenters planning on advertising their business in comments: please be informed that I'm NOT going to post your comments but will ALWAYS mark them as SPAM.