Download a .mp3 link and save it to computer with PHP(下载 .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.
这篇关于下载 .mp3 链接并使用 PHP 将其保存到计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:下载 .mp3 链接并使用 PHP 将其保存到计算机
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01