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


Download a .mp3 link and save it to computer with PHP

我在一个.txt文件中有很多直接的.mp3链接,我想保存在我的计算机上(如下:http://mylink.mp3),我想知道如何使用PHP实现这一点?

我应该使用file_get_contents吗?

(很抱歉,如果我的问题已经在这里得到回答,我搜索了一下,但对我没有帮助)

谢谢:)。

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

您可能希望避免循环,因为下载大量文件可能会占用资源。