2010-08-20 121 views
2

因此,我有一个mp3文件的url,我需要将其保存到一个特定的目录。如何做到这一点的最好办法,有人告诉我,卷曲但有一些PHP命令的副本文件,这将使这个过程变得更容易下载文件并保存到PHP中的目录中

回答

6
copy($url, $destination); 

copy

+0

更好:--D。 – NawaMan 2010-08-20 16:23:29

+0

甚至比wget +1更好 – 2011-03-14 19:22:13

0

确保也同时修改了允许你的网页执行时间处理时间。大多数页面只允许30秒,特别是如果您通过HTTP页面(网页)进行此操作。你需要做到这一点,以匹配下载文件需要多长时间。

1
<?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); 
?> 
0

很容易:-D

$URL = ...; // Like "http:// ...." 
$FileToSave = ...;  // Like "/home/.." or "C:/..." 
$Content = file_get_contents($URL); 
file_put_contents($FileToSave, $Content);

希望这有助于。