chmod 777 in php

。_饼干妹妹 提交于 2019-12-01 06:53:51

问题


If I create a folder in php with mkdir() it has the www-data : www-data user and 755 permissions.

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.

How can I make the created folders and uploaded files readable / removeable for both the www-data and the ftp-user?


回答1:


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.

The above function returns a booleon to let you know either it has succeed in changing the entities permissions.

if(!chmod($directory,0777))
{
    echo "Unable to chmod $direcotry";
}

Also a quote from 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.

Understanding above you should look at chown




回答2:


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.




回答3:


by default when you create a folder in *nix other users will not have the ability to delete/modify the folder.

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

Note don'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




回答4:


Remove the double quote and try and also check for the owner of file

chmod($path, 0777) 


来源:https://stackoverflow.com/questions/5019194/chmod-777-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!