First, let's get these out of the way:
- There are no open handles on the directory.
- There are no files in the directory.
chmod
ing the permissions to 0777 does not prevent the error.- the directory name is correct.
Now then, here's my problem. rmdir()
is throwing this error when trying to delete the directory:
rmdir(098f6bcd4621d373cade4e832627b4f6) [function.rmdir]: Permission denied in path\to\administrate.php on line 124
098f6bcd4621d373cade4e832627b4f6 is the name of the directory.
Here is the relevant portion of the script.
if(is_dir($userhash)) :
foreach (new DirectoryIterator($userhash) as $fileInfo) {
$fileName = $fileInfo->getFilename();
if($fileInfo->isDot()) continue;
if(!rename($userhash.'/'.$fileName , 'trashcan/'.$username.'/'.$fileName)) {
echo '<p class="error">Could not move '.$fileName.'</p>';
$err = 1;
}
}
else :
echo '<p class="error">Unable to delete files! error: 67</p>';
$err = 1;
endif;
//JUST TO BE SURE
chmod('./',0777);
chmod($userhash,0777);
// RMDIR ONCE THE DIR IS EMPTY.
if(rmdir($userhash))
echo '<p class="success">Deleted the user directory. The files are in the trash.</p>';
else {
echo '<p class="error">Could not remove the user directory. Error: 656</p>';
$err = 1;
}
Update
I manually created the dir 'jake'
in the same directory. I did rmdir('jake');
and it worked great. Now, I manually created a dir '098f6bcd4621d373cade4e832627b4f6'
in the same directory. I did rmdir('098f6bcd4621d373cade4e832627b4f6');
and it errored!
Update 2
This is beginning to look like some weird rmdir()
bug, as unlikely as that seems. Here are directory names I've created and then tried to remove with rmdir
;
098f6bcd4621d373cade4e832627b4f6 | didn't work (quintuple checked)
098f6bcd4621d373cade4e832627b4f7 | worked
098f6bcd4621d373cade4e832627b4f | worked
098f6bcd4621d373cade4e832627b4f66 | worked
In order to be able remove file:
UPDATE: About restricted deletion flag - from
man chmod
:You may SET it by adding 1 to the first octal digit in mode, for example:
UPDATE 2:
Does user, under which php is executed, has permissions to chmod parent directory?
In other words, are you sure that first chmod call returns true?