With a simple html and js file, how can I get an mp3 download link instead of just playing?

I have a link to a multimedia file, such as mp3, and I want it to load when the user clicks on it, instead of just playing the file. the page I have in mind is just a static html page.

any ideas?

+5
source share
8 answers

For this to happen, you need to send a heading with a heading Content-disposition: attachment; filename=fname.extto your favorite language before sending the file.

, , , . html javascript.

+5

, . , , , , + . , php apache, .htacces

<FilesMatch "\.(?i:mp3)$">
  ForceType audio/mpeg
  Header set Content-Disposition attachment
</FilesMatch>

MP3 :

<FilesMatch "\.(?i:mp3)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>

php .: http://nl.php.net/header

+3

smazurov, , Content-disposition . RFC , .

0

JavaScript ( document.execCommand('SaveAs'), html-).

0

google, js. . ( 2003 , ).

php, asp , , : -)

0
<a href="linkto.mp3" download>Download MP3 File </a>
0

, , download ( ):

<a href="file.mp3" download="Song_Name.mp3">Download</a>

, , URL- , . HTML JS. , , , .

0

, , MP3. .

-1
source

All Articles