Page 1 of 1

Permission denied?

Posted: Mon Mar 24, 2003 9:08 am
by phice
When I run this on my Win98 system, it runs just fine. Yet, when I try it using my linux machine, it gives the error:

Deleting a file:
Warning: unlink() failed (Permission denied) in /home/nncommunity/www/phpFF/list_files.php on line 109
Removing a folder:
Warning: chmod failed: Operation not permitted in /home/nncommunity/www/phpFF/list_files.php on line 82

Warning: rmdir() failed (Permission denied) in /home/nncommunity/www/phpFF/list_files.php on line 91
function:

Code: Select all

<?php
function delete($file) {
 if (file_exists($file)) {
   chmod($file,0777);
   if (is_dir($file)) {
     $handle = opendir($file); 
     while($filename = readdir($handle)) {
       if ($filename != "." && $filename != "..") {
         delete($file."/".$filename);
       }
     }
     closedir($handle);
     rmdir($file);
   } else {
     unlink($file);
   }
 }
return TRUE;
}
?>
On my win98 machine, it will clean out the directory if it isn't empty, then will delete the folder.

Any help?

Posted: Mon Mar 24, 2003 9:21 am
by twigletmac
Have you checked you've set all the required permissions?

Mac

Posted: Mon Mar 24, 2003 9:46 am
by phice
Which required permissions do I need? Would I have to CHMOD the parent directory before deleteing anything inside it first?

Posted: Mon Mar 24, 2003 11:16 am
by twigletmac
You'd need IIRC read + write permissions on the parent directory.

Mac

Posted: Mon Mar 24, 2003 5:14 pm
by phice
Gah, could you clarify what's needed? I don't see why I can't rmdir() a directory in linux. :/

Posted: Tue Mar 25, 2003 4:41 am
by twigletmac
I would assume that you need to have write permission on the folder from which you are trying to delete the files - if you only had read permission then you wouldn't be able to modify the folder's files only look at them. That's possibly where the errors are coming from. What's the permissions currently on the parent directory?

Mac

Posted: Tue Mar 25, 2003 6:07 pm
by phice
phpFF/ - 775 (parent directory to where the folders/files (i wish to delete using rmdir() and unlink()) reside in
phpFF/asdf/ - 775 - (folder I wish to delete using rmdir()) completely nothing inside

Posted: Tue Mar 25, 2003 7:52 pm
by m3mn0n
777

Posted: Tue Mar 25, 2003 8:37 pm
by phice
Amazing.

Posted: Wed Mar 26, 2003 12:19 am
by phice
Ok, so I've got it working and I know exactly what I need done to delete files and folders.

The parent directory of the desired folder/file has to be CHMOD'd to 777. This may result in an error, in example if the user CHMODs a folder to something like 755, then it'll be unable to delete files/folders inside that folder.

I'm pondering on a function that'll check if the parent directory is CHMOD'd to 777, if not, then it'll CHMOD that directory. Yet, this could easily result in a problem.


Any ideas?

Posted: Wed Mar 26, 2003 2:07 am
by luisquijada
Are you sure your both, windows linux http servers, have the same configuration, permissions, etc., about target directory?

Posted: Wed Mar 26, 2003 9:01 am
by phice
On the windows machine it works just fine, but the linux server keeps saying the permission is denied, if the parent folder isn't CHMODed to 777.

If the parent folder is CHMOD'd to 777, then it works.