2015-08-15 84 views
1

我有一个问题,我要访问的URL cURL只有我得到的消息:卷曲如何与文件

404未找到


而当我写如下因素的命令,它作品。我不明白,

curl "http://stream.song365.co/h/2747175/Arctic%20Monkeys%20-%20R%20U%20Mine%3F_(song365.cc).mp3" 

这里是我的代码:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'http://stream.song365.co/h/2747175/Arctic%20Monkeys%20-%20R%20U%20Mine%3F_(song365.cc).mp3'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_REFERER,'https://www.song365.co/'); 
$output = curl_exec($ch); 
curl_close($ch); 
return $output; 

回答

0

你可以使用

$url = "http://stream.song365.co/h/2747175/Arctic%20Monkeys%20-%20R%20U%20Mine%3F_(song365.cc).mp3"; 
$fp = fopen (dirname(__FILE__) . '/file.mp3', 'w+'); // where the file will be downloaded 
$ch = curl_init(str_replace(" ","%20",$url)); // replace the url spaces with %20 
curl_setopt($ch, CURLOPT_TIMEOUT, 50); 
curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_REFERER,'http://www.song365.co/'); 
curl_exec($ch); // get curl response 
curl_close($ch); 
fclose($fp); 
+0

这工作,谢谢! :) –