Mr.Nikan Mr.Nikan - 1 year ago 63
PHP Question

forcing to download mp3 link instead of streaming it

i been looking and i could not find a way to force to save a mp3 file ( from link )
i found this that works with the files on same host Like

or a/x.mp3

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

but how can i do this for mp3 links which stream instead of downloading it ?

thanks in advance

Answer Source

In HTML use:

<a download href="file.mp3">

In modern browsers it forces download.

This also allows you to avoid using PHP to serve that particular file. By default PHP prevents download resumption and makes serving relatively expensive for your server.