V
V
Vladimir Mogila2021-04-25 13:15:38
PHP
Vladimir Mogila, 2021-04-25 13:15:38

Permission denied when trying to write a file?

Guys, I really ask for help, I have already climbed the entire Internet, and for the 3rd day I have been trying to understand what the trouble is.

The task seemed to be simpler than simple in fact. But I can’t cope.

As I understand it, the problem is in the server, it doesn’t want to upload photos by any method, I also tried through
file_put_contents ($ path, file_get_contents ($ url)); and through curl, and the result is one error.

The first option, according to the idea, is simpler and easier, and I thought to choose it. but bad luck, it gives an error:

Array ( [type] => 2 [message] => file_put_contents(/var/www/www-root/data/www/mytelegrambot.club/escooter/img/users_img/5555ror.jpg) : failed to open stream: Permission denied [file] => /var/www/www-root/data/www/mytelegrambot.club/escooter/upload.php [line] => 29 )

and this is where my search began, I created all files under root, access in the users_img folder set both 777 and 755, and 666, generally 0 to mass, and tried Apache settings so that it runs scripts from root, it starts everything from root, there is order, the folder is also in order, the code is also in order, I have already copied a million examples, it would seem that everything should work, but in the example it works, but I don’t.

I don't know what to do, from the word at all, help kind people, maybe someone solved this trouble

The code looks like this:
$url = ' https://www.google.com.ua/logos/doodles/2016/earth... ';
$path = $_SERVER['DOCUMENT_ROOT'] . '/escooter/img/users_img/5555ror.jpg';
file_put_contents($path, file_get_contents($url));

the whole site is in my "escooter" folder, it has img and users_img in it,
I run the script from the root, essentially from the escooter folder

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Mogila, 2021-05-14
@vim-studio

Who will have such a problem, check the permissions in the parent folder, for the images folder, it turned out that the whole trouble is in it, for example:
/img_1/
img_user above error.
Thanks to everyone who opened my eyes, I hope it helps someone

N
nejmatovich, 2021-04-30
@nejmatovich

Few inputs. What OS? What user is apache running under? Directory permissions? Owner? Is SELinux enabled?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question