Skip to content

Instantly share code, notes, and snippets.

@devpilot
Created December 24, 2011 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devpilot/1516754 to your computer and use it in GitHub Desktop.
Save devpilot/1516754 to your computer and use it in GitHub Desktop.
Delete directory with content in it
<?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