下载 .mp3 链接并使用 PHP 将其保存到计算机
我想保存在我的计算机上的 .txt 文件中有很多直接 .mp3 链接(例如:http://mylink.mp3 ),我想知道如何使用 PHP 做到这一点?
I've got lots of direct .mp3 links in a .txt file that I'd like to save on my computer (like this: http://mylink.mp3 ), and I was wondering how I could do this with PHP ?
我应该使用 file_get_contents 吗?
Should I use file_get_contents ?
(对不起,如果我的问题已经在这里得到解答,我搜索了但它没有帮助我)
(Sorry if my questions was already answered here, I searched but it didn't help me)
谢谢你:).
推荐答案
$file = 'http://somewebsite.com/thesong.mp3';
header("Content-type: application/x-file-to-save");
header("Content-Disposition: attachment; filename=".basename($file));
readfile($file);
您可能希望避免循环,因为下载大量文件可能会占用资源.
You probably will want to avoid looping as downloading a lot of files can be a resource sucker.
相关文章