download mp3 instead of playing in browser by default?

前端 未结 1 1552
猫巷女王i
猫巷女王i 2020-12-06 03:27

I have a site where users can stream my music from a flash player or download the individual songs (as mp3s). Right now if you click on the download links, they just play i

相关标签:
1条回答
  • 2020-12-06 04:00

    You will need to add this HTTP header to your response to make the browser force a download:

    Content-Disposition: attachment; filename=your_filename.mp3
    

    For example, if you're using PHP on the server side, you can create a script that sends the above header followed by the actual file contents:

    $path = $_GET['path'];
    header('Content-Disposition: attachment; filename=' . basename($path));
    readfile($path);
    

    If you call this script download.php, then linking to download.php?path=/path/to/your/file.mp3 will make the browser pop-up a download dialog for file.mp3.

    0 讨论(0)
提交回复
热议问题