Skip to content

Instantly share code, notes, and snippets.

@perudesarrollo
Last active June 22, 2021 10:42
Show Gist options
  • Save perudesarrollo/6af574678708ac4d12ddc22dfcccb935 to your computer and use it in GitHub Desktop.
Save perudesarrollo/6af574678708ac4d12ddc22dfcccb935 to your computer and use it in GitHub Desktop.
using imgur api v3 to upload images
$client_id = 'xxxxxxxx';
$file = file_get_contents("test-image.png");
$url = 'https://api.imgur.com/3/image.json';
$headers = array("Authorization: Client-ID $client_id");
$pvars = array('image' => base64_encode($file));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL=> $url,
CURLOPT_TIMEOUT => 30,
CURLOPT_POST => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => $pvars
));
$json_returned = curl_exec($curl); // blank response
echo "Result: " . $json_returned ;
curl_close ($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment