Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing playing an MP3 file using an HTML anchor

Tags:

html

How do you make an MP3 link download instead of play "in-browser"?

I tried changing the target to blank, but that just opened the player in a new window.

like image 764
Chris Mccabe Avatar asked Jan 22 '23 02:01

Chris Mccabe


2 Answers

You can't do this by modifying the link. You will have to have the HTTP server that serves the file send a Content-Type of "application/octet-stream". Presumably it is sending the type "audio/mpeg", which is hinting to the browser that it is MP3 content. Without the capacity to alter this header, you can't achieve this.

like image 61
cdhowie Avatar answered Feb 01 '23 22:02

cdhowie


If your server supports PHP, create a PHP script called "getfile.php" (or similar) that takes a parameter of a file ID or file name. Set the content-type and content-disposition headers within the script to force a download prompt.

See: http://webdesign.about.com/od/php/ht/force_download.htm

like image 37
Evan Mulawski Avatar answered Feb 01 '23 22:02

Evan Mulawski