Home > Article > Backend Development > php traverses sub-files under a folder
function my_scandir($dir) { $files=array(); if(is_dir($dir)) { if($handle=opendir($dir)) { while(($file=readdir($handle))!==false) { if($file!=”.” && $file!=”..”) { if(is_dir($dir.”/”.$file)) { $files[$file]=my_scandir($dir.”/”.$file); } else { $files[]=$dir.”/”.$file; } } } closedir($handle); return $files; } } }
The above introduces PHP to traverse the sub-files under a folder, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.