How to Use PHP to Delete All Folders and Files?

Some web hosting companies do not allow us to use “system(‘rm -rf ./*’); ” to delete contents, but we do really need to delete all sub folders and files quickly, how to then?

The follow php code can help us:

<DOCTYPE html>
<meta charset=”utf-8″ />
<?php
function delDirAndFile( $dirName )
{
if ( $handle = opendir( “$dirName” ) ) {
while ( false !== ( $item = readdir( $handle ) ) ) {
if ( $item != “.” && $item != “..” ) {
if ( is_dir( “$dirName/$item” ) ) {
delDirAndFile( “$dirName/$item” );
} else {
if( unlink( “$dirName/$item” ) )echo “Files deleted successfully? $dirName/$item\n”;
}
}
}
closedir( $handle );
if ( rmdir( $dirName ) ) echo “Files deleted successfully: $dirName\n”;
}
}
// delDirAndFile( ‘wap’);  del a folder called: wap
delDirAndFile( ‘./’);  //del all sub folders and files under the current folder
?>
King Php Science Welcome, you are from: 54.166.203.76