PHP - Deleting Directory Contents & SubDirectory Contents
function empty_dir($dir) {
    $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir),
                                              RecursiveIteratorIterator::CHILD_FIRST);
    foreach ($iterator as $path) {
      if ($path-&gt;isDir()) {
         rmdir($path-&gt;__toString());
      } else {
         unlink($path-&gt;__toString());
      }
    }
    rmdir($dir);
}


from: http://php.net/manual/en/class.recursivedirectoryiterator.php