2013-08-01 21 views
2
$image = file_get_contents($_FILES['upload']['tmp_name']); 
    $id = 'myid'; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, 'https://api.imgur.com/3/image.json'); 
    curl_setopt($ch, CURLOPT_POST, TRUE); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $id)); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image))); 
    $response = curl_exec($ch); 
    curl_close($ch); 
    $response = json_decode($response); 

這是我必須將匿名圖像上傳到imgur的引用塊。它可以在我的Mac OS機器上運行xampp,但它不適用於我的windows上的xampp。我也知道以下關於捲曲窗口xampp:cURL請求正在從imgur api獲得NULL響應

-it is enabled 
-it works when i try to grab the content of an url 
-it doesnt work when i try to make DELETE request to remove an anonymous image(the same code works on the mac os xampp) 

我覺得有兩個計算機上的cURL設置之間的一些區別。我會很感激,如果你能告訴我的方式!提前致謝。

+0

如果你在你的'的phpinfo看()',有一個名爲「捲翹部」。嘗試比較這些。 – Mike

+0

查看輸出了哪些cURL錯誤'echo curl_error();'這可能是CA的問題,然後在這種情況下,您需要使用正確的cURL函數指向它。 – Vector

+0

可怕的無恥插件:您可以使用Runscope檢查請求/響應數據,而無需在代碼中轉儲出響應。這樣你就可以看到實際的API響應是什麼。 –

回答

6

這是一個SSL問題。請嘗試以下線的curl_exec呼叫

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

之前(你可以添加var_dump($response);查看服務器響應。)

+0

我想嘗試一下,非常感謝你! –

+0

完全工作,再次感謝您! –

+1

不客氣。請接受答案。謝謝。 –