Answer the question
In order to leave comments, you need to log in
How to upload an image to your server?
Hello!
I am writing authorization through Google and it became necessary to upload the user's avatar to my server.
Google sends me a response that has a link to the avatar:
"picture": "https://lh6.googleusercontent.com/-sdKkMmClA5M/BABBBBBBDI/AAAAABAAAQg/4SjnUI7UOsQ/s96-c/photo.jpg"
$picture = $token_info['picture'];
$sourcecode=GetImageFromUrl($picture);
$savefile = fopen('/var/www/html/uploads/avatars/image.jpg', 'w');
fwrite($savefile, $sourcecode);
fclose($savefile);
function GetImageFromUrl($link) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_URL,$link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
return $result;
}
fopen(): failed to open stream: Permission denied
sudo usermod -a -G user_main www-data
sudo chmod -R 750 /var/www/html/uploads/avatars/
You don't have permission to access /upload_avatar on this server.
Answer the question
In order to leave comments, you need to log in
I don’t know how you have everything set up there, but you can try to do the following:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Allow From All
Require all granted
</Directory>
fopen(): failed to open stream: Permission denied
is an error due to the fact that Google gives a 404 error on the link to the photo, Not Found (image not found)
and then you have to play with the rights, put 777 for sure)
stackoverflow.com/questions/724391/saving-image-fr...
If that doesn't work, it's obviously a permissions issue. This is already a separate issue.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question