chmod 777 in php

前端 未结 4 977
无人共我
无人共我 2021-01-14 15:11

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

相关标签:
4条回答
  • 2021-01-14 15:42
    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

    0 讨论(0)
  • 2021-01-14 15:46

    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.

    0 讨论(0)
  • 2021-01-14 15:50

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

    chmod($path, 0777) 
    
    0 讨论(0)
  • 2021-01-14 15:52

    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

    0 讨论(0)
提交回复
热议问题