我想將遠程圖像保存到使用php curl的文件,但文件永遠不會保存!任何人可以幫助我如何解決這個問題?圖像文件永遠不會被創建,但echo $ returned_content有數據!如何使用php curl將遠程圖像保存到文件?
<?
$returned_content = get_data('http://somesite.com/43534545345dfsdfdsfdsfds.jpg');
echo $returned_content;
$fp = fopen('43534545345dfsdfdsfdsfds.jpg', 'w');
fwrite($fp, $returned_content);
fclose($fp);
/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
當U回聲$ returned_content你看到的數據?還要將'w'改爲'wb' – craftand
謝謝reply.yes我看到數據。我應該把哪個chmod文件夾放在沒有產生安全問題的php腳本中? – user1788736
755應該是正常的 – craftand