SO i have a url of an mp3 file and i need to save it to a specific directory. How is the best way to do this, someone told me curl but is there a copy file of some ph开发者_C百科p command that will make this process easier
copy($url, $destination);
copy
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://amanjain.com/path-to-mp3.mp3');
//Create a new file where you want to save
$fp = fopen('filename.mp3', 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec ($ch);
curl_close ($ch);
fclose($fp);
?>
Very easy :-D
$URL = ...; // Like "http:// ...."
$FileToSave = ...; // Like "/home/.." or "C:/..."
$Content = file_get_contents($URL);
file_put_contents($FileToSave, $Content);
Hope this helps.
Make sure also you also modify your pages allowed execution time. Most pages only allow 30 seconds, especially if you are doing this over a HTTP page (a webpage). You need to up this to match how long it actually takes to download the file.
精彩评论