我的网站上有一个上传图片功能。我在我的localhost中尝试过,它工作正常。现在我托管了它,发生了以下错误:
移动上传的文件无法打开流权限被拒绝
我在网上检查了错误,发现通过将chmod更改为777,可以解决。
我尝试了同样的方法,但它确实奏效了。即使只是713工作正常。但由于黑客入侵的可能性,给予777许可是不好的。
有解决方法吗?我现在已经将chmod更改为713,直到我能为此获得更好的解决方案。
我目前使用Ubuntu 16.04图像托管在Google Cloud Platform中
答案 0 :(得分:1)
You can use 2 options.
1) you can change the owner from the upload directory to the apache user
chmod www-data:www-data your_folder
but this has some negative effects. your ssh user can edit files here just with root privileges.
2) you can create a group only for upload files and put your ssh user and the apache user into this group
sudo addgroup uploaders
sudo usermod -aG uploaders www-data
sudo usermod -aG uploaders your_user
after this change the owner of the upload folder
chmod your_user:uploaders your_folder
after this you can change the permissions to 744 or something you want