1

I'm using MashApe API to upload images to Imgur using PHP as follows:

$valid_file_extensions = array(".jpg", ".jpeg", ".gif", ".png");

        $file_extension = strrchr($_FILES["file"]["name"], ".");

        if (in_array($file_extension, $valid_file_extensions)) {
            if (@getimagesize($_FILES["file"]["tmp_name"]) !== false) {

                $filename = $_FILES['file']['tmp_name'];
                $handle = fopen($filename, "r");
                $data = fread($handle, filesize($filename));

                $response = Unirest\Request::post("https://imgur-apiv3.p.mashape.com/3/image",
                    array(
                        "X-Mashape-Key" => "key",
                        "Authorization" => "Client-ID ID",
                        "Content-Type" => "application/x-www-form-urlencoded"
                    ),
                    array(
                        "image" => base64_encode($data)
                    )
                );

                var_dump(base64_encode($data));
                $result = json_decode($response->raw_body);

                if ($result->success) {
                    var_dump($result);
                } else {
                    $Pointer->Bootstrap()->Alert($result->data->error, "danger");
                }

            }
        }

but it always give me the following error: Image is corrupted or format is not supported.

Sebastian Brosch
  • 42,106
  • 15
  • 72
  • 87
Abanoub
  • 3,623
  • 16
  • 66
  • 104

1 Answers1

-2

If you downloaded a webm and changed the file type to gif when you saved it, the conversion is too corrupt for imgur. Try Cloudconvert until one of us figures out how to do it offline.

I recommend ShareX for automatic uploads to imgur.

Erlja Jkdf.
  • 171
  • 2
  • 12