我现在的凭据是正确的。
当我通过这样的表单发送图像时:(action="http://api.imageshack.com/v2/images/")。它工作正常但是当我尝试发送 $ch = curl_init($url); 它失败了。
代码:
enter code here
<form action="" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="file" id="file" multiple>
<input type="text" name="auth_token" id="auth_token" value="xxxxxxxxxxxxxxxx">
<input type="text" name="api_key" id="api_key" value="xxxxxxxxxxxxxxx">
<input type="submit" value="Upload Image" >
</form>
$url = ' http://api.imageshack.com/v2/images/ ';
$temp = $_FILES["file"]['tmp_name'];
echo $temp."<br>" ;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'file'=> '@'.$temp,
"key" => "xxxxxxxxxxxxxxxxxxxx",
"auth_token" => "xxxxxxxxxxxxxxx"
));
curl_exec($ch);
我也尝试过使用 Header: curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
我从 imageshack 得到错误为 json: {"error_code":1,"error_message":"无效的图像文件。上传的文件未被检测为图像文件。","error_info":{"Content-Type":空,“文件大小”:0}}