4

OK help me understand this.

I have 2 users in my linux system that are BOTH part of "web-users" group.

one is www-data used by the webserver and php-cgi one is my 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 (so same group like the ftp user) to delete that directory and files inside: unlink for files works ok but the command rmdir doesnt work returning permission denied!? And yes the directory is deleted after is emptied.

why is that 775 means that the group's user can delete it just like 664 for files.

Thanks!

3 Answers 3

2

You might check the permissions of the parent that contains the directory you're trying to delete.

I was deleting some script-generated directories earlier this week and even with their permissions set to 777, I was still getting "permission denied" until I gave myself Write access to the parent directory.

0

I encountered the same problem before and my code looked like below:

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 it was permission issue but it turned out that I just needed to call closedir before rmdir-ing. So:

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

Maybe your problem is similar to mine?

0
-2

You can't use rmdir() on a directory that contains files. The directory must be empty before you use rmdir() to delete it.

1
  • 1
    Read the question completely before you answer.
    – codaddict
    Sep 6, 2010 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.