Home > Article > Backend Development > How to recursively delete directories and files in php, _PHP tutorial
The example in this article describes the method of recursively deleting directories and files in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
<?php function deldir($path){ $dh = opendir($path); var_dump(readdir($dh)); while(($d = readdir($dh)) !== false){ if($d == '.' || $d == '..'){//如果为.或.. continue; } $tmp = $path.'/'.$d; if(!is_dir($tmp)){//如果为文件 unlink($tmp); }else{//如果为目录 deldir($tmp); } } closedir($dh); rmdir($path); } $path = "./e"; deldir($path); ?>
I hope this article will be helpful to everyone’s PHP programming design.