Question

I am using php to upload images to imgur this is the code i am using:

    $id = 'clientId';
    $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 ' . $id));
    curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'image' => base64_encode($image)));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
    $response = json_decode($response);
    curl_close ($ch);

The code is working but i want the images to be upload to my account album if anyone know how to do it, Also i am trying to understand why do i have to set curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); for the code to work, I did visit the manual but if anyone can give me some background about how and why i will be very thankful, Thank you all and have a nice day.

Was it helpful?

Solution

You can send these parameters with your request:

image   required    A binary file, base64 data, or a URL for an image
album   optional    The id of the album you want to add the image to. For anonymous albums, {album} should be the deletehash that is returned at creation.
type    optional    The type of the file that's being sent; file, base64 or URL
name    optional    The name of the file, this is automatically detected if uploading a file with a POST and multipart / form-data
title   optional    The title of the image.
description optional    The description of the image.

So, how about this:

curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image), 'album' => 1234));

OTHER TIPS

By setting CURLOPT_SSL_VERIFYPEER to false, it will not verify the domain on the ssl certificate. Usually a certificate is set to xyz.com domain and not all of the xyz's subdomains (more expensive since those certs are less common).

Since it works when you set it to false, it means that their ssl certificate is not created for the specific domain path.

By setting to true, it will try to validate the certificate and will stop the connection if the certificate does not exist for that specific domain path. Hope that's helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top