Permission denied?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Permission denied?

Post 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?
Image Image
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you checked you've set all the required permissions?

Mac
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Which required permissions do I need? Would I have to CHMOD the parent directory before deleteing anything inside it first?
Image Image
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You'd need IIRC read + write permissions on the parent directory.

Mac
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Gah, could you clarify what's needed? I don't see why I can't rmdir() a directory in linux. :/
Image Image
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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
Image Image
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

777
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

Amazing.
Image Image
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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?
Image Image
luisquijada
Forum Newbie
Posts: 2
Joined: Wed Mar 26, 2003 2:07 am

Post by luisquijada »

Are you sure your both, windows linux http servers, have the same configuration, permissions, etc., about target directory?
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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.
Image Image
Post Reply