In this tutorial, We will learn how to delete the directory and files in the directory. You can understand the concept of PHP remove folders and all files.


Example:

<?php
  
$folderName = 'images2';
  
removeFiles($folderName);
   
function removeFiles($target) {
    if(is_dir($target)){
        $files = glob( $target . '*', GLOB_MARK );
  
        foreach( $files as $file ){
            removeFiles( $file );      
        }
  
        rmdir( $target );
    } elseif(is_file($target)) {
        unlink( $target );  
    }
}
  
?>


Thanks, I hope it will help you.....