Skip to content

Instantly share code, notes, and snippets.

@nao-pon
Created July 17, 2012 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nao-pon/3128915 to your computer and use it in GitHub Desktop.
Save nao-pon/3128915 to your computer and use it in GitHub Desktop.
<?php
class rmdir_recursive
{
private function rmdir($path) {
if (is_dir($path)) {
if ($handle = opendir($path)) {
while (false !== ($entry = readdir($handle))) {
if ($entry !== '.' && $entry !== '..' && !$this->rmdir($path . DIRECTORY_SEPARATOR . $entry)) {
return false;
}
}
closedir($handle);
}
if (! @rmdir($path)) {
return false;
}
} else {
if (! @unlink($path)) {
return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment