Created
July 17, 2012 11:32
-
-
Save nao-pon/3128915 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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