Created
January 9, 2023 05:03
-
-
Save Yohn/05e3dfdc2e960dcd709ac2597e355704 to your computer and use it in GitHub Desktop.
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 | |
function emptyDirectory($dirname,$self_delete=false){ | |
if(is_dir($dirname)) | |
$dir_handle = opendir($dirname); | |
if(!$dir_handle) | |
return false; | |
while($file = readdir($dir_handle)){ | |
if($file != "." && $file != ".."){ | |
if (!is_dir($dirname."/".$file)) | |
@unlink($dirname."/".$file); | |
else | |
emptyDirectory($dirname.'/'.$file,true); | |
} | |
} | |
closedir($dir_handle); | |
if($self_delete){ | |
@rmdir($dirname); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment