Skip to content

Instantly share code, notes, and snippets.

@jpgcode
Last active December 30, 2015 06:09
Show Gist options
  • Save jpgcode/7787265 to your computer and use it in GitHub Desktop.
Save jpgcode/7787265 to your computer and use it in GitHub Desktop.
Remove folders recursively with PHP
function rrmdir($file) {
if (is_dir($file)) {
$objects = scandir($file);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($file."/".$object) == "dir") $this->rrmdir($file."/".$object); else unlink($file."/".$object);
}
}
reset($objects);
rmdir($file);
}else{
unlink($file);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment