TO GET ALL FILES ON RECURSIVE DIRECTORIES IN SINGLE ARRAY USE THE CODE GIVEN BELOW.
function getFilesFromDir($dir) {
$files = array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(is_dir($dir.'/'.$file)) {
$dir2 = $dir.'/'.$file;
$files[] = getFilesFromDir($dir2);
}
else {
$files[] = $dir.'/'.$file;
}
}
}
closedir($handle);
}
return $this->array_flat($files);
}
function array_flat($array) {
foreach($array as $a) {
if(is_array($a)) {
$tmp = array_merge($tmp, array_flat($a));
}
else {
$tmp[] = $a;
}
}
return $tmp;
} // Code to get folder contents (Usage) $dir = '/data'; $foo = $this->getFilesFromDir($dir); print_r($foo); ?>
With Regards,
Er.Animesh Nanda
Sr. Programmer Analyst,
Innovate Search Pvt. Ltd..
Bengaluru,Karnataka,INDIA.