Imgur に画像をアップロードするために数週間前に作成したこのスクリプトを確認してください。
Imgur.php
<form enctype="multipart/form-data" method="post" action="imgur.php">
Choose your file here:
<input name="file" type="file"/>
<input type="submit" value="Upload It"/>
</form>
if(isset($_FILES['file']))
{
$filename = $_FILES['file']['tmp_name'];
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
print_r(imgur($data));
}
else
{
echo "Nothing Done";
}
function imgur($data)
{
$key = "IMGUR KEY";
$pvars = array('image' => base64_encode($data), 'key' => $key);
$timeout = 30;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/2/upload.json');
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
$json = curl_exec($curl);
$json = json_decode($json,true);
$res['small'] = substr($json['upload']['links']['small_square'],19) . "<br />";
$res['original'] = substr($json['upload']['links']['original'],19) . "<br />";
$res['delete'] = $json['upload']['image']['deletehash'] . "<br />";
curl_close ($curl);
return $res;
}
?>
それは私とうまく動作します。