-
-
Save yoren/4335368 to your computer and use it in GitHub Desktop.
PHP: Delete directory and its content
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
<?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