i am writing a php page that let the user to upload his profile image to the database sql but i am getting these errors i tried many solutions i found online but i couldn't know how to fix my code , i would really appreciate your time i am a new developer . thank you in advance :
the errors are :
( ! ) 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:\wamp64\www\final-project\classes\Image.php on line 22
Call Stack
# Time Memory Function Location
1 0.0009 381752 {main}( ) ...\my-account.php:0
2 0.0175 439648 Image::uploadImage( ) ...\my-account.php:33
3 0.0224 789608 file_get_contents ( ) ...\Image.php:22
( ! ) Notice: Trying to get property of non-object in C:\wamp64\www\final-project\classes\Image.php on line 25
Call Stack
# Time Memory Function Location
1 0.0009 381752 {main}( ) ...\my-account.php:0
2 0.0175 439648 Image::uploadImage( ) ...\my-account.php:33
( ! ) Notice: Trying to get property of non-object in C:\wamp64\www\final-project\classes\Image.php on line 25
Call Stack
# Time Memory Function Location
1 0.0009 381752 {main}( ) ...\my-account.php:0
2 0.0175 439648 Image::uploadImage( ) ...\my-account.php:33
./classes/Image.php:
<?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 a5d4b7d7eb41f3c2049e1212c628996839cc3066\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);
}
}
?>
this is the php page given to the user so he can upload his profile picture to the database.
if (Login::isLoggedIn()) {
$userid = Login::isLoggedIn();
} else {
die('Not logged in!');
}
if (isset($_POST['uploadprofileimg'])) {
Image::uploadImage('profileimg', "UPDATE users SET profileimg = :profileimg WHERE id=:userid", array(':userid'=>$userid));
Image();
}
?>