-
-
Save bablukpik/68a10f55a6ba87433685d9f1ab17d5de to your computer and use it in GitHub Desktop.
PHP: Remove directory and its contents
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
/** | |
* Remove the directory and its content (all files and subdirectories). | |
* @param string $dir the directory name | |
*/ | |
function rmrf($dir) { | |
foreach (glob($dir) as $file) { | |
if (is_dir($file)) { | |
rmrf("$file/*"); | |
rmdir($file); | |
} else { | |
unlink($file); | |
} | |
} | |
} | |
//OR | |
To delete all files in a folder: | |
array_map('unlink', glob("$dirname/*.*")); | |
And then we can remove the folder: | |
rmdir($dirname); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment