Download a .mp3 link and save it to computer with PHP

时光毁灭记忆、已成空白 提交于 2019-12-06 12:15:00

问题


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 :).


回答1:


$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.



来源:https://stackoverflow.com/questions/18196117/download-a-mp3-link-and-save-it-to-computer-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!