下载 .mp3 链接并使用 PHP 将其保存到计算机 [英] Download a .mp3 link and save it to computer with PHP

查看:36
本文介绍了下载 .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 将其保存到计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆