I want to delete folder i use this code :- rmdir($folder); Code (markup): but if folder contain some file or some folders then i will get this error :- Now i ant to delete all files and folder along with the main folder so how to do that ?
The comments on the PHP documentation page are very useful to read, they contains answers to many common questions. From http://ca.php.net/manual/en/function.rmdir.php : <?php function rmdir_r($path) { if (!is_dir($path)) {return false;} $stack = Array($path); while ($dir = array_pop($stack)) { if (@rmdir($dir)) {continue;} $stack[] = $dir; $dh = opendir($dir); while (($child = readdir($dh)) !== false) { if ($child[0] == '.') {continue;} $child = $dir . DIRECTORY_SEPARATOR . $child; if (is_dir($child)) {$stack[] = $child;} else {unlink($child);} } } return true; } ?> Code (markup):