Php does not remove 775 dir chmod

OK help me figure this out.

I have 2 users on my Linux system that are part of the BOTH group "web users".

one is the www data used by the web server, and php-cgi is my one ftp user

when I upload files via ftp, they are set to 775 for dirs and 664 for files, when I run a script on the server (just like the ftp user group) to delete this directory and files inside: unlink for files work fine, but rmdir command does not work, returning permission denied !? And yes, the directory is deleted after release.

why is this 775 meaning that the group user can delete it in the same way as 664 for files.

Thank!

+3
source share
3 answers

You can check permissions parentwhich contains the directory that you are trying to delete.

I deleted some script-generated directories earlier this week, and even with their permissions set to 777, I still got a "permission denied" until I gave myself Writeaccess to the directory parent.

+1
source

I ran into the same problem and my code looked like this:

function recurse_delete_dir($dir) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            if ($file != '.' && $file != '..') {
                 $child_file = $dir . $file;
                 if (is_dir($child_file)) {
                     recurse_delete_dir($child_file);
                 }
                 else {
                     unlink($child_file);
                 }
            }
        }
        rmdir($dir);
    }
}

I myself thought that this was a problem with resolution, but it turned out that I just needed to call closedirbefore rmdir-ing. So:

closedir($dh);
rmdir($dir);

Perhaps your problem is similar to mine?

0
source

rmdir() , . , rmdir(), .

-2

Source: https://habr.com/ru/post/1763430/


All Articles