1000000 || $file['error'] == UPLOAD_ERR_INI_SIZE) {
exit('Sorry, your file is too large');
}
if (!exif_imagetype($file['tmp_name'])) {
exit('File is not an image');
}
if ($file['error'] == UPLOAD_ERR_OK) {
$fh = fopen($file['tmp_name'], 'r');
$read = fread($fh, $file['size']);
fclose($fh);
$post = array(
'image' => base64_encode($read)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Client-ID '.$client_id
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch); // Response, info: https://api.imgur.com/#responses
curl_close($ch);
// $image = json_decode($json, true); // Array
$image = json_decode($json); // Object
// var_dump($image);
// $original = $image['data']['link']; // Array-style
$original = $image->data->link; // Object-style
$thumb = substr_replace($original, 't', -4, 0); // t = Small Thumbnail, info: https://api.imgur.com/models/image
echo '
'.$original.''; // Example
// ...
}
else {
echo 'Upload was failed. Error code: '.$file['error'];
}
}
break;
default:
echo ''."\n"
.''."\n"
.'
Upload an image to imgur.com.
'."\n" .'© 20161209 nggit
'."\n" .'