2013-08-28 14 views
1

FB PHP API和php 5.5上傳照片到服務器時出現問題。當使用方法:FB API PHP curl_setopt_array():棄用文件上傳的@filename API

private function _upload($type = '', $path = '', $message = '', $aid = '') { 
     try { 

      if (!in_array($type, array('photos', 'videos'))) { 
       throw new \Exception('Error: Incorrect type '); 
      } 

      if (!self::getFB()->getUser()) { 
       throw new \Exception('Error: No user'); 
      } 

      if (empty($path)) { 
       throw new \Exception('Error: path is empty'); 
      } 
      if (!file_exists(realpath($path))) { 
       throw new \Exception('Error: file doesn\'t exists'); 
      } 


      if (!empty($aid)) { 
       $url = "/" . $aid . "/" . $type; 
      } else { 
       $url = '/' . self::getFB()->getUser() . '/' . $type; 
      } 

      var_dump(array($url, 'POST', 

        array(
         'image' => '@' . realpath($path), 
         'message' => $message, 
        ) 
       ) 
      ); 

      self::getFB()->setFileUploadSupport(TRUE); 

      $ret_obj = self::getFB()->api($url, 'POST', array(
        'image' => '@' . realpath($path), 
        'message' => $message, 
       ) 
      ); 
      return $ret_obj[ 'id' ]; 
     } catch (\Exception $e) { 
      return $e->getMessage(); 
     } 
    } 

我得到錯誤:curl_setopt_array():在@filename API文件上傳的用法已過時。請使用CURLFile類代替

+1

您應該創建一個bug報告,要求他們更新SDK採取這一變化考慮在內,https://開頭開發商。 facebook.com/bugs Btw。,是否真的是一個錯誤消息,會破壞你的腳本,還是隻是一個警告? (「已棄用」意味着在將來某個時間點不再工作,但現在仍然有效,因此這應該只是一個警告而不是腳本中斷錯誤。) – CBroe

+0

由於服務器上的設置會產生錯誤。 – xAqweRx

回答

3

您正在使用PHP 5.5以舊方式通過CURL上傳。退房的差異在https://wiki.php.net/rfc/curl-file-upload

curl_setopt($curl_handle, CURLOPT_POST, 1); 
$args['file'] = '@filename.png'; 
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args); 

curl_setopt($curl_handle, CURLOPT_POST, 1); 
$args['file'] = new CurlFile('filename.png', 'image/png'); 
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $args);