Linux php中的chmod 777
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5019194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
chmod 777 in php
提问by Yens
If I create a folder in php with mkdir() it has the www-data : www-data user and 755 permissions.
如果我使用 mkdir() 在 php 中创建一个文件夹,它具有 www-data : www-data 用户和 755 权限。
The problem is I can't delete this folder with the ftp-user (zapbe:psasrv) I tried to modify the folder with chmod($path, "0777") in php but this doesn't work.
问题是我无法使用 ftp-user (zapbe:psasrv) 删除此文件夹我尝试在 php 中使用 chmod($path, "0777") 修改该文件夹,但这不起作用。
How can I make the created folders and uploaded files readable / removeable for both the www-data and the ftp-user?
如何使创建的文件夹和上传的文件对 www-data 和 ftp-user 都可读/可删除?
采纳答案by RobertPitt
bool chmod ( string $filename , int $mode )
Within PHP they might be some limitations on the security, therefore the depending on your configuration it may not work.
在 PHP 中,它们可能对安全性有一些限制,因此根据您的配置,它可能不起作用。
The above function returns a booleon to let you know either it has succeed in changing the entities permissions.
上面的函数返回一个 booleon,让您知道它是否已成功更改实体权限。
if(!chmod($directory,0777))
{
echo "Unable to chmod $direcotry";
}
Also a quote from PHP:
还有一段来自 PHP 的引用:
The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.
当前用户是运行 PHP 的用户。它可能与您用于普通 shell 或 FTP 访问的用户不同。只有在大多数系统上拥有该文件的用户才能更改该模式。
Understanding above you should look at chown
上面的理解你应该看看chown
回答by Shakti Singh
Remove the double quote and try and also check for the owner of file
删除双引号并尝试检查文件的所有者
chmod($path, 0777)
回答by Patrick
by default when you create a folder in *nix other users will not have the ability to delete/modify the folder.
默认情况下,当您在 *nix 中创建文件夹时,其他用户将无法删除/修改该文件夹。
to change the permissions of the www-data created folder, run the command in a php script from the browser and it should update successfully
要更改创建的 www-data 文件夹的权限,请在浏览器中的 php 脚本中运行该命令,它应该会成功更新
Notedon't put the new permissions in double quotes, it needs to be an octal number
注意不要把新的权限放在双引号中,它需要是一个八进制数
chmod($path, 0777);
// not chmod($path, "0777);
Once you do that anyone can modify the folder
一旦你这样做任何人都可以修改文件夹
回答by Costi Ciudatu
In order to remove a directory, you need to have write permissions on the parent directory, not on the one you want to remove. In order to provide write access on the parent, a good approach would be to make that parent owned by some group that both www-data and your ftp user are members of, and never use the 777 permissioning. Also, make sure your parent folder does not have the sticky bit set.
为了删除目录,您需要对父目录具有写权限,而不是要删除的目录。为了提供对父级的写访问权限,一个好的方法是让该父级由 www-data 和您的 ftp 用户都是其成员的某个组拥有,并且永远不要使用 777 权限。另外,请确保您的父文件夹没有设置粘性位。