2012-07-13 82 views
0

我試圖在重定向後檢索圖像的位置URL,但似乎無法使其工作。我從來沒有使用cURL,但從我做的研究看來,我需要它從Facebook獲取圖像。這裏是我到目前爲止的代碼:從cURL請求的頭部獲取位置

function getImage($url) { 
$ch = curl_init(); 
// Only calling the head 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, true); // header will be at output 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD' 

$content = curl_exec($ch); 
curl_close($ch); 

return $content; 
} 

$image = explode("Location: ", getImage("http://graph.facebook.com/553451657/picture?type=large")); 

print_r($image); 

但我的反應是:

HTTP/1.1 302 Found Access-Control-Allow-Origin: * Cache-Control: private, no-cache, no-store, must-revalidate Content-Type: image/jpeg Expires: Sat, 01 Jan 2000 00:00:00 GMT Location: http://profile.ak.fbcdn.net/hprofile-ak-snc4/161877_553451657_798840908_n.jpg Pragma: no-cache X-FB-Rev: 590433 X-FB-Debug: WH1uJvIjUqiLT8ezVPdude8VKYnXjAHRlFaP8gqF9fI= Date: Fri, 13 Jul 2012 17:56:09 GMT Connection: keep-alive Content-Length: 0 Array ([0] => 1) 

如何我只是得到了部分的位置(「http://profile.ak.fbcdn.net/hprofile-ak -snc4/161877_553451657_798840908_n.jpg「)?

回答

-1

如何我只是得到了部分的位置

獲得該Location頭是不是你主要目標,對不對?你想從被重定向到的地址獲取圖像,是否正確?

所以剛纔設置的選項CURLOPT_FOLLOWLOCATION,和捲曲將遵循自動重定向並獲取真正像你。