Created
December 19, 2012 21:32
-
-
Save irazasyed/4340722 to your computer and use it in GitHub Desktop.
PHP: Remove directory and its contents
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
/** | |
* Remove the directory and its content (all files and subdirectories). | |
* @param string $dir the directory name | |
*/ | |
function rmrf($dir) { | |
foreach (glob($dir) as $file) { | |
if (is_dir($file)) { | |
rmrf("$file/*"); | |
rmdir($file); | |
} else { | |
unlink($file); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if error not found method rmrf
use:
if (is_dir($file)) {
$this->rmrf("$file/*");
rmdir($file);
}
or if use this method in another methos static
use:
if (is_dir($file)) {
self::rmrf("$file/*");
rmdir($file);
}
💯