1

I'm trying to write a very simple test to upload an image to imgur and then redirect to the imgur page once it's done. (haven't gotten to that point yet)

I've looked all around these forums and tried so many different codes posted here, as well as cobbled some together from various posts. Finally, I've stopped getting errors in the php.

But.. in every code I've seen, it displays the image once it's done. Using that exact same code, my image does not appear, all I get is a page with Result: and nothing more. Does anyone have any idea what could be the problem?

<html>
<body>
  <form action="upload_img.php" method="post" enctype="multipart/form-data">
        <input type="file" name="imgupload" /><br>
        <input type="submit" value="Upload to Imgur" />
  </form>
</body>
</html>

and the php file:

<?php

    $client_id = '$clientIDHERE';

        $file = file_get_contents($_FILES["imgupload"]["tmp_name"]);

        $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); 

?>
JayOverflow
  • 11
  • 1
  • 3
  • http://stackoverflow.com/questions/19977933/php-uploading-multiple-images-to-imgur-at-once –  Aug 14 '14 at 15:46

1 Answers1

0

Before you close the $curl handle you should check for errors:

if ($error = curl_error($curl)) {
    die('cURL error:'.$error);
}
Sverri M. Olsen
  • 13,055
  • 3
  • 36
  • 52
  • Thanks for the reply, Seems I'm getting an SSL error....... Result: cURL error:SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed ---- What does one do about that? – JayOverflow Mar 20 '14 at 22:21
  • Ah, I fixed it with the solution here: http://stackoverflow.com/a/12293898/3443902 – JayOverflow Mar 20 '14 at 22:31