I am using Imgur to upload photos from my site.
This is my code
$client_id = '*********';
$image = file_get_contents($_FILES['update_profile_photo']['tmp_name']);
$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 $client_id"));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image)));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$reply = curl_exec($ch);
curl_close($ch);
$reply = json_decode($reply);
echo "<h3>Image</h3>";
printf('<img height="180" src="%s" >', $reply->data->link);
echo "<h3>API Debug</h3><pre>";
var_dump($reply);
When I first upload a file it printed out the image. But from the next try I am unable to view the file and in laravel I get an error like this
when clear printf('<img height="180" src="%s" >', $reply->data->link);
to check the result of var_dump()
, it gives me like this
object(stdClass)#219 (3) {
["data"]=>
object(stdClass)#215 (3) {
["error"]=>
object(stdClass)#212 (4) {
["code"]=>
int(1016)
["message"]=>
string(27) "Banned country attempt (IN)"
["type"]=>
string(16) "Exception_Logged"
["exception"]=>
array(0) {
}
}
["request"]=>
string(13) "/3/image.json"
["method"]=>
string(4) "POST"
}
["success"]=>
bool(false)
["status"]=>
int(400)
}
I am living in India (It is telling in message that Banned Country attempt)
I want to know how to fix this error? Why first time it worked and now it dont.
I am in localhost, didnt host yet.
Is this problem of my code?
Please tell me how to fix this
Imgur is blocked in India, so you are unable to access the API.
The only reliable way to fix this, is to access the API through a proxy.
Source: http://thehackernews.com/2015/01/indian-government-blocks-32-sites.html