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

查看:96
本文介绍了下载一个.mp3链接并使用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);

你可能会想避免循环,因为下载很多文件可能是一个资源吸盘。 p>

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 ?

Should I use file_get_contents ?

(Sorry if my questions was already answered here, I searched but it didn't help me)

Thank you :).

解决方案

$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天全站免登陆