Skip to content

Instantly share code, notes, and snippets.

@hadifarnoud
Created December 26, 2014 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadifarnoud/5a047fda2338b42480cd to your computer and use it in GitHub Desktop.
Save hadifarnoud/5a047fda2338b42480cd to your computer and use it in GitHub Desktop.
function deleteDirectory($dir) {
if (!file_exists($dir)) {
return true;
}
if (!is_dir($dir)) {
return unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
return rmdir($dir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment