php中通过DirectoryIterator删除整个目录的方法

<?php

function cleanup_directory($dir) {
  foreach (new DirectoryIterator($dir) as $file) {
    if ($file->isDir()) {
      if (!$file->isDot()) {
        cleanup_directory($file->getPathname());
      }
    } else {
      unlink($file->getPathname());
    }
  }
  rmdir($dir);
}
?>

SyntaxHighlighter.highlight();