Created
November 24, 2017 14:53
-
-
Save e-vural/867fa5545eacda1007c99ed59e36b045 to your computer and use it in GitHub Desktop.
Delete All Directory And Files In a Directory
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
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