Re: How to delete non-empty directory??
| From: | David Newcomb | Date: | Wed, 27 Sep 2000 09:20:24 +0000 |
| Subject: | Re: How to delete non-empty directory?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17664@lists.php.net to get a copy of this message | ||
> Believe me. I tried that. If the directory is empty it
> deletes but if the directory is not empty it does not
> delete anything. I even tried to chdir to the
> directory to delete the files first then go one level
> up to delete the directory. It did not work either.
> Check the code below:
>
> $path = "/path/to/thedir/to/delete/";
>
> $dir_name = "bbb";
>
> $directory = "$path/$dir_name";
>
> chdir($directory);
>
> $dir = opendir(".");
> while($file = readdir($dir)){
> unlink($file);
> }
>
> chdir("..");
>
> system("rm -rf $directory");
>
> what is going on. Why can't I delete NON-empty
> directory? Any idea?
This is a permissions problem. It will be simplier to
re-write the program as:
<?php
system("rm -rf $path/$dir_name");
?>
When you run the program check the /usr/local/apache/log/error_log
(or equiv) for any output/error from running the "rm" command.
The user who runs that web server is probably different to the
user who owns the filesystem directories. If you want to delete the
directory
then the webserver user must have write permission on the directory
above the one you want to delete.
hope that makes sense,
David.
the reason why the