The error I get:
Warning: file_get_contents(https://api.imgur.com/3/image): failed to open stream: HTTP request failed! HTTP/1.1 403 Permission Denied in C:\xampp\htdocs\sn0\classes\Image.php on line 22
Notice: Trying to get property of non-object in C:\xampp\htdocs\sn0\classes\Image.php on line 25
Notice: Trying to get property of non-object in C:\xampp\htdocs\sn0\classes\Image.php on line 25
Here's my Image.php file:
<?php
class Image {
public static function uploadImage($formname, $query, $params) {
$image = base64_encode(file_get_contents($_FILES[$formname]['tmp_name']));
$options = array('http'=>array(
'method'=>"POST",
'header'=>"Authorization: Bearer ###\n".
"Content-Type: application/x-www-form-urlencoded",
'content'=>$image
));
$context = stream_context_create($options);
$imgurURL = "https://api.imgur.com/3/image";
if ($_FILES[$formname]['size'] > 10240000) {
die('Image too big, must be 10MB or less!');
}
$response = file_get_contents($imgurURL, false, $context);
$response = json_decode($response);
$preparams = array($formname=>$response->data->link);
$params = $preparams + $params;
DB::query($query, $params);
}
}
?>
Authentication required
, i.e. you need to provide some form of authentication to use the API endpoint. Imgur has a pretty nice API documentation at apidocs.imgur.com – you should probably give that a read. – Florian Link Aug 24 '18 at 14:51