The following editor will bring you a simple example of the recursive algorithm for php to obtain all files in a folder. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.
is as follows:
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 is the detailed content of PHP gets all files in a folder (recursive algorithm). For more information, please follow other related articles on the PHP Chinese website!