下载.mp3链接并使用PHP将其保存到计算机

时间:2013-08-12 20:29:28

标签: php download save mp3

我在.txt文件中有很多直接的.mp3链接,我想保存在我的电脑上(比如:http://mylink.mp3),我想知道如何用PHP做到这一点?

我应该使用file_get_contents吗?

(对不起,如果我的问题已经在这里得到解答,我搜索了但它没有帮助我)

谢谢你:)。

1 个答案:

答案 0 :(得分:3)

$file = 'http://somewebsite.com/thesong.mp3'; 
header("Content-type: application/x-file-to-save"); 
header("Content-Disposition: attachment; filename=".basename($file)); 
readfile($file);

您可能希望避免循环,因为下载大量文件可能是资源傻瓜。