Created
January 12, 2017 16:04
-
-
Save Kruithne/4f0b4bb73b4be9d8f692a8935d05a488 to your computer and use it in GitHub Desktop.
Recursive PHP File Deleteion
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
function rmrf($dir) | |
{ | |
foreach (scandir($dir) as $node) | |
{ | |
if ($node == "." || $node == "..") | |
continue; | |
$path = $dir . DIRECTORY_SEPARATOR . $node; | |
if (is_dir($path)) | |
rmrf($path); // Directory, explore deeper. | |
else | |
unlink($path); // File | |
} | |
rmdir($dir); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment