with just a plain html and js file, how can i force a link to an mp3 to download instead of just play?

前端 未结 7 2118
误落风尘
误落风尘 2021-01-13 15:50

i have a link to a media file such as an mp3, and i want it to get downloaded when the user clicks on it, instead of just having the file get played. the page i have in min

7条回答
  •  日久生厌
    2021-01-13 16:26

    Is far is I know that's not possible. Without the ability to set the appropriate headers the browser will decide what to do with the file, which usually is playback, you will have to ask to users to press, right-click+save as. If you have access to the server it is quite simple to set the headers in php or apache using .htacces

    
      ForceType audio/mpeg
      Header set Content-Disposition attachment
    
    

    Or so the browser won't recognize it's an MP3 and won't even try opening it:

    
      ForceType application/octet-stream
      Header set Content-Disposition attachment
    
    

    For php header setting see: http://nl.php.net/header

提交回复
热议问题