我在.txt文件中有很多直接的.mp3链接,我想保存在我的电脑上(比如:http://mylink.mp3),我想知道如何用PHP做到这一点?
我应该使用file_get_contents吗?
(对不起,如果我的问题已经在这里得到解答,我搜索了但它没有帮助我)
谢谢你:)。
答案 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);
您可能希望避免循环,因为下载大量文件可能是资源傻瓜。