Created
January 3, 2023 09:52
-
-
Save MaximeCulea/a3f9938095ffe16af791d77cfd226070 to your computer and use it in GitHub Desktop.
PHP Helpers
This file contains hidden or 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 a folder recursively | |
* | |
* @param $dir | |
* | |
* @author Maxime CULEA | |
*/ | |
private function delete_folder( $dir ) { | |
if ( ! is_dir( $dir ) ) { | |
return; | |
} | |
$objects = scandir( $dir ); | |
foreach ( $objects as $object ) { | |
if ( $object != "." && $object != ".." ) { | |
if ( is_dir( $dir . DIRECTORY_SEPARATOR . $object ) && ! is_link( $dir . "/" . $object ) ) { | |
rrmdir( $dir . DIRECTORY_SEPARATOR . $object ); | |
} else { | |
unlink( $dir . DIRECTORY_SEPARATOR . $object ); | |
} | |
} | |
} | |
rmdir( $dir ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment