Skip to content

Instantly share code, notes, and snippets.

@e-vural
Created November 24, 2017 14:53
Show Gist options
  • Save e-vural/867fa5545eacda1007c99ed59e36b045 to your computer and use it in GitHub Desktop.
Save e-vural/867fa5545eacda1007c99ed59e36b045 to your computer and use it in GitHub Desktop.
Delete All Directory And Files In a Directory
public function deleteDirectory($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != '.' && $object != '..') {
(filetype($dir . '/' . $object) == 'dir') ? $this->deleteDirectory($dir . '/' . $object) : unlink($dir . '/' . $object);
}
}
reset($objects);
return rmdir($dir) ? true : false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment