Last active
May 2, 2019 18:56
-
-
Save gabyfle/d7e74e70da6efbeab1c3b2f9636dc178 to your computer and use it in GitHub Desktop.
Deletes recursively a directory from the server's disk
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
<?php | |
/** | |
* Delete recursively a directory | |
* Gist : https://gist.github.com/Gabyfle/d7e74e70da6efbeab1c3b2f9636dc178 | |
* | |
* @param string $path | |
*/ | |
function delete_directory(string $path): void | |
{ | |
$files = new \DirectoryIterator($path); | |
foreach ($files as $file) { | |
if ($file->isDot() === false) { | |
if($file->isFile()) { | |
unlink($file->getPathname()); | |
} elseif ($file->isDir()) { | |
self::delete_directory($file->getPathname()); | |
} | |
} | |
} | |
rmdir($path); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment