Skip to content

Instantly share code, notes, and snippets.

@Yohn
Created January 9, 2023 05:03
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 Yohn/05e3dfdc2e960dcd709ac2597e355704 to your computer and use it in GitHub Desktop.
Save Yohn/05e3dfdc2e960dcd709ac2597e355704 to your computer and use it in GitHub Desktop.
<?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