Skip to content

Instantly share code, notes, and snippets.

@yoren
Forked from devpilot/del_dir.php
Created December 19, 2012 08:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoren/4335368 to your computer and use it in GitHub Desktop.
Save yoren/4335368 to your computer and use it in GitHub Desktop.
PHP: Delete directory and its content
<?php
/**
* Delete directory with content in it
* @author Pilot
* @param string $directory Directory to delete
*/
function del_dir($directory) {
$content = scandir($directory);
unset($content[0], $content[1]);
foreach ($content as $filename) {
if (is_dir($path = $directory . '/' . $filename)) {
del_dir($path);
} else {
unlink($directory . '/' . $filename);
}
}
rmdir($directory);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment