我試圖保存來自Facebook的圖像並出現問題。使用curl保存facebook圖像,file_get_contents,fopen/fread/fwrite,複製 - 奇怪的標題
它運作良好,除了圖片來自域external.ak.fbcdn.net
使用curl,的file_get_contents,FOPEN/FREAD/FWRITE,複製迴歸的1x1 GIF圖片,而不是實際的圖像。
我coudn't找到解決辦法,所以我查了一下上面的URL(get_headers)發佈標題和獲取GIF:
array(10) {
[0]=>
string(15) "HTTP/1.0 200 OK"
["Content-Type"]=>
string(9) "image/gif"
["Pragma"]=>
string(8) "no-cache"
["X-FB-Debug"]=>
string(44) "qcXPNe3kW3TLOCgBRQQUBr/ekWiKISQTqbdUbDi7vXs="
["X-Cnection"]=>
string(5) "close"
["Content-Length"]=>
string(2) "43"
["Cache-Control"]=>
string(44) "private, no-cache, no-store, must-revalidate"
["Expires"]=>
string(29) "Sat, 31 Mar 2012 20:52:23 GMT"
["Date"]=>
string(29) "Sat, 31 Mar 2012 20:52:23 GMT"
["Connection"]=>
string(5) "close"
}
是否有人可以幫助我?這是一種Facebook保護或我做錯了什麼?
以防萬一,這裏是我的捲曲代碼:
$ch = curl_init($url);
$fp = fopen($filePath, 'wb');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
[保存的facebook可能重複使用cURL](http://facebook.stackoverflow.com/questions/9680676/save-facebook-profile-image-using-curl) – ifaour 2012-03-31 21:26:31
acualy no - 我正確保存配置文件圖像並將FOLLOWLOCATION設置爲true – John 2012-03-31 21:35:50