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中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01