用其中的文件删除目录[重复]

Possible Duplicate:
PHP: delete directory with files in it?

If i've some files inside the following path

mysite.com/install

and i've created file named as "die.php" outside /install/ where its path mysite.com/die.php once i executed it, it should delete install folder with all its files inside.

I've added to die.php the following code

<?PHP rmdir('install');?>

but it only delete /install/ folder when it is empty ! and if it have files it gives error Directory not empty in mysite.com/install

so any idea how to do it.

This should work

<?php
 function rrmdir($dir) {
   if (is_dir($dir)) {
     $objects = scandir($dir);
     foreach ($objects as $object) {
       if ($object != "." && $object != "..") {
         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
       }
     }
     reset($objects);
     rmdir($dir);
   }
 }
?>

I found it on the php site. This seems to be a common issue.

If you're looking for a pure PHP solution, you will have to loop though all subfolders (see answer just posted above). For a faster approch that only works on a platform with GNU coreutils (any major Linux distribution), use this:

system('rm -rf '.$dir);

A word of advice: This is potentially unsafe (possible to pipe a command) - be very sure to sanitize your input.