强制下载mp3链接而不是流式传输


forcing to download mp3 link instead of streaming it

我一直在寻找,但找不到强制保存mp3文件的方法(来自链接)我发现这个可以和同一主机上的文件一起使用,比如x.mp3或/x.mp3

<?php
    $file = $_GET['file'];
    header("Content-type: octet/stream");
    header("Content-disposition: attachment; filename=".$file.";");
    header("Content-Length: ".filesize($file));
    readfile($file);
    exit;
?>

但是,我如何才能做到这一点的mp3链接流,而不是下载它?像

http://ahmusm.mubox.in/nevisande/aliz/mp3/1395/02/05/Beyonce%20-%20Hold%20Up.mp3

提前感谢

在HTML中使用:

<a download href="file.mp3">

在现代浏览器中,它强制下载。

这也允许您避免使用PHP来提供特定的文件。默认情况下,PHP会阻止下载恢复,并使服务器的服务成本相对较高。