简体   繁体   English

/ var / www中上传文件的权限

[英]Permissions of uploaded files in /var/www

I have a picture folder in the website directory and every time i upload pictures into that directory, they have the wrong permissions and i have to manually change the permissions so that i could alter the images or rotate them, delete, copy etc. Is there a way to automatically change the permissions of the uploaded files in that specific folder. 我在网站目录中有一个图片文件夹,每次我将图片上传到该目录,他们都有错误的权限,我必须手动更改权限,以便我可以改变图像或旋转它们,删除,复制等。是否有一种自动更改该特定文件夹中上载文件权限的方法。 May be there is some permission field in Apache configurations that can be changed. 可能是Apache配置中有一些可以更改的权限字段。 Please help! 请帮忙! Thank you. 谢谢。

Most likely the user running the webapp is www-data (for ubuntu/debian based OS). 运行webapp的用户很可能是www-data(基于ubuntu / debian的OS)。 If the user you are logging in to your box is a different, the best you can do is to setup a group and make that group own /var/www - or only the folder you really need. 如果您登录到您的盒子的用户不同,那么您可以做的最好的事情是设置一个组并使该组拥有/var/www - 或者只有您真正需要的文件夹。 The group should hold the both users: 该组应该拥有这两个用户:

add a group: 添加一个组:

sudo groupadd <name of the group> // whatever you prefer

Now that the group exists, add the two users to it: 既然该组存在,请将两个用户添加到其中:

sudo usermod -a -G usergroup <your username> // the one you login with
sudo usermod -a -G usergroup www-data

Now all that's left is to set the permissions on the directory: 现在剩下的就是设置目录的权限:

sudo chgrp -R usergroup /var/www
sudo chmod -R 775 /var/www     

Now only members of the usergroup group can read, write, or execute files and folders within the directory. 现在,只有用户组组的成员才能读取,写入或执行目录中的文件和文件夹。 Note the -R argument to the chmod and chgrp commands: this tells them to recurse into every sub directory of the target directory and modify every file and directory available. 注意chmod和chgrp命令的-R参数:这告诉他们递归到目标目录的每个子目录并修改每个可用的文件和目录。

Please note that group assignment changes won't take effect until the users log out and back in. 请注意 ,在用户注销并重新登录之前,组分配更改不会生效。

You can use chmod in PHP to change the permissions. 您可以在PHP中使用chmod来更改权限。 http://php.net/manual/en/function.chmod.php http://php.net/manual/en/function.chmod.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM