【问题标题】:uploading using Mashape to upload to imgur always says image corrupted or not format not supported使用 Mashape 上传到 imgur 总是说图像损坏或不支持格式
【发布时间】:2016-01-06 23:05:39
【问题描述】:

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

$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.

【问题讨论】:

    标签: php base64 imgur mashape


    【解决方案1】:

    如果您下载了 webm 并在保存时将文件类型更改为 gif,则转换对于 imgur 来说太损坏了。尝试Cloudconvert,直到我们中的一个人弄清楚如何离线操作。

    我推荐 ShareX 自动上传到 imgur。

    【讨论】:

      猜你喜欢
      • 2016-07-17
      • 2015-01-12
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      相关资源
      最近更新 更多