【发布时间】:2013-08-02 21:52:30
【问题描述】:
$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。我也知道以下关于 windows xampp 上 curl 的知识:
-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 设置之间存在一些差异。如果你能告诉我方法,我将不胜感激!提前致谢。
【问题讨论】:
-
如果你查看你的
phpinfo(),有一个名为“curl”的部分。尝试比较这些。 -
查看输出了哪些 cURL 错误
echo curl_error();这可能是 CA 的问题,在这种情况下,您需要使用正确的 cURL 函数指向它。 -
非常无耻的插件:您可以使用 Runscope 来检查请求/响应数据,而无需在代码中转储响应。这样您就可以看到实际的 API 响应是什么。