I have the following function:
function listFiles($dir, $results = array()){
$entities = is_dir($dir) ? array_values(array_diff(scandir($dir), array('..', '.'))) : false ;
if( $entities )
foreach( $entities as $e ) {
$path = $dir.'/'.$e;
if( is_dir($path) ) {
listFiles($path, $results);
}
$results[] = $path;
}
return $results;
}
print_r(listFiles('/home/apps/public_html/test_folder'));
Although this works somehow the array has only the first branch of the directory. But if I echo the path inside foreach I get the path of every file from all folders and subfolders and so on.
Probably this is something very small but I can't figure out what and I could use some help. Thank you.