Last active
September 15, 2021 14:51
-
-
Save SimonDevelop/fd1172aa04d8972e4995c5c5da6df617 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
function deleteDir($dirPath) { | |
if (!is_dir($dirPath)) { | |
throw new InvalidArgumentException("$dirPath must be a directory"); | |
} | |
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { | |
$dirPath .= '/'; | |
} | |
$files = glob($dirPath . '*', GLOB_MARK); | |
foreach ($files as $file) { | |
if (is_dir($file)) { | |
deleteDir($file); | |
} else { | |
unlink($file); | |
} | |
} | |
rmdir($dirPath); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment