2015-10-09 24 views
1

我使用MashApeAPI上傳圖片到Imgur上傳使用Mashape上傳到imgur總是說圖像損壞或不格式,採用<code>PHP</code>如下不支持

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

回答

-2

如果您下載了webm並在保存文件時將文件類型更改爲gif,則imgur的轉換過於腐敗。嘗試Cloudconvert,直到我們其中一個人瞭解如何離線執行此操作。

我推薦ShareX自動上傳到imgur。

相關問題