使用Mashape上传到imgur总是说图像损坏或不支持格式化

时间:2015-10-09 05:51:45

标签: php base64 imgur mashape

我使用MashApe API使用Imgur将图片上传到PHP,如下所示:

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

            }
        }

但它总是给我以下错误:Image is corrupted or format is not supported.

1 个答案:

答案 0 :(得分:-2)

如果你下载了webm并在保存时将文件类型更改为gif,那么转换对于imgur来说太过腐败了。尝试Cloudconvert,直到我们中的一个人知道如何离线。

我建议将ShareX自动上传到imgur。