Define recursive function to delete directories
<?php function delete_directory($dir) { if ($dh = @opendir($dir)) { while (($file = readdir ($dh)) != false) { if (($file == ".") || ($file == "..")) continue; if (is_dir($dir . '/' . $file)) delete_directory($dir . '/' . $file); else unlink($dir . '/' . $file); } @closedir($dh); rmdir($dir); } } $dir = "./fakeDir"; delete_directory($dir); ?>