Skip to content

Instantly share code, notes, and snippets.

@Kruithne
Created January 12, 2017 16:04
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 Kruithne/4f0b4bb73b4be9d8f692a8935d05a488 to your computer and use it in GitHub Desktop.
Save Kruithne/4f0b4bb73b4be9d8f692a8935d05a488 to your computer and use it in GitHub Desktop.
Recursive PHP File Deleteion
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