2012-03-26 69 views
1

我試圖通過圖形api檢索用戶顯示圖片,並使用cUrl將其保存到磁盤中,但無法成功並在嘗試檢查MIME時出現此錯誤無法通過cURL檢索並保存用戶的顯示圖片

Notice: exif_imagetype(): Read error! in

//$userPpicture = $user_profile[picture]; 
//Create image instances 
     $url = "http://graph.facebook.com/{$userId}/picture?type=large"; 
     $dpImage = 'temp/' . $userId . '_dpImage_' . rand().'.jpg'; 
     echo $dpImage; 

     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); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
      $data = curl_exec($ch); 
      curl_close($ch); 
      return $data; 
     } 

     $returned_content = get_data($url); 
     file_put_contents($dpImage, $returned_content); 
     echo "Type: " . exif_imagetype($dpImage); 

使用curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);我收到此錯誤此更新的代碼:

Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in /var/fog/apps/app12345/myapp.phpfogapp.com/start.php on line 178

01,我保存的圖片類型

如果此操作需要任何服務器端配置的話,我可能不會爲我使用一個共享的雲存儲在phpfog能夠做到這一點。

請幫助我。

三江源。

+0

你確定權限給予了應用程序訪問的圖片? – Reinard 2012-03-26 14:48:01

+0

是所有必需的權限。 – Maven 2012-03-26 14:49:26

+0

@Sir - 通過/ id /圖片的照片公開可用 - Maven - 查看臨時目錄中的圖像 - 檢查你是否得到你所期望的 - 還可以嘗試file_get_contents(它適用於URL) – scibuff 2012-03-26 14:50:30

回答

2

您使用的http://graph.facebook.com/4/picture?type=large圖表URL返回一個HTTP 302重定向,而不是實際用戶的圖像。您需要按照重定向並在該url下載圖像,該url爲如下所示的url:http://profile.ak.fbcdn.net/hprofile-ak-snc4/49942_4_1525300_n.jpg

+0

感謝您的回覆,我遵循了您的建議,允許cURL採取行動(請參閱我的更新代碼),但現在我得到了新的警告。請幫忙。 – Maven 2012-03-27 04:47:57

1

正如OffBySome指出的那樣,您需要遵循graph.facebook.com提供的302重定向到最終目的地,其中包含實際的圖像數據。

最簡單的方法做,在這種情況下,以添加CURLOPT_FOLLOWLOCATION作爲真正的另一curl_setopt電話。即

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true)

退房http://us3.php.net/manual/en/function.curl-setopt.php瞭解更多詳情。

+0

感謝您的回覆,做到了這一點,但現在我得到了新的警告。 (請參閱我的更新代碼),請幫助。 – Maven 2012-03-27 04:48:45