1

Trying to make script which uploading image on imgur anonymously. Just blank page when I run it. I need to post image(in base 64 string format) with title and description. Sorry for my english and code.

<?
header ("Content-type: image/png");  
    $im = ImageCreate (200, 100);     
    $couleur_fond = ImageColorAllocate ($im, 255, 0, 0);  
  $client_id="d9514d92012b55a";
  $pvars   = base64_encode($im);
  $timeout = 30;
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image.json');
  curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id . ', title: title, description: description'));
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
  $out = curl_exec($curl);
  curl_close ($curl);
  $pms = json_decode($out,true);
  $url=$pms['data']['link'];


?>
  • related: http://stackoverflow.com/questions/4372710/php-curl-https – AllInOne Jun 22 '16 at 22:16
  • It looks like your code came from [this blog post](http://subinsb.com/uploading-images-using-imgur-api-in-php). Your code seems to be missing some things and your `client_id` is invalid. I just set it up using the code from that blog post and a valid `client_id` and it is working fine. – APAD1 Jun 22 '16 at 22:21

1 Answers1

0

If you're trying to print the url in the end, you should remove the header ("Content-type: image/png");.

Explanation: header ("Content-type: image/png"); tells the browser to behave with the content as image while it is a plain text or html...


You should also use full php tag <?php instead of the short one <?

Explanation: Some servers do not interpret php code starting with short php tag and send the code to browser as plain text.

Riad Loukili
  • 119
  • 8