我正在写一个php页面,让用户将他的个人资料图片上传到数据库sql但我得到这些错误我尝试了很多我在网上找到的解决方案,但我不知道如何修复我的代码,我会真的感谢您的时间我是一名新开发者。提前谢谢你:
错误是:
( ! ) 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
./类/ 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);
}
}
?>
这是给用户的php页面,因此他可以将他的个人资料图片上传到数据库。
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();
}
?>