Skip to content

Instantly share code, notes, and snippets.

@MaximeCulea
Created January 3, 2023 09:52
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 MaximeCulea/a3f9938095ffe16af791d77cfd226070 to your computer and use it in GitHub Desktop.
Save MaximeCulea/a3f9938095ffe16af791d77cfd226070 to your computer and use it in GitHub Desktop.
PHP Helpers
<?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