Skip to content

Instantly share code, notes, and snippets.

@SimonDevelop
Last active September 15, 2021 14:51
Show Gist options
  • Save SimonDevelop/fd1172aa04d8972e4995c5c5da6df617 to your computer and use it in GitHub Desktop.
Save SimonDevelop/fd1172aa04d8972e4995c5c5da6df617 to your computer and use it in GitHub Desktop.
<?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