function pc_process_dir($dir_name,$max_depth = 10,$depth = 0) {
if ($depth >= $max_depth) {
error_log("Reached max depth $max_depth in $dir_name.");
return false;
}
$subdirectories = array();
$files = array();
if (is_dir($dir_name) && is_readable($dir_name)) {
$d = dir($dir_name);
while (false !== ($f = $d->read())) {
// skip . and ..
if (('.' == $f) || ('..' == $f)) {
continue;
}
if (is_dir("$dir_name/$f")) {
array_push($subdirectories,"$dir_name/$f");
} else {
array_push($files,"$dir_name/$f");
}
}
$d->close();
foreach ($subdirectories as $subdirectory) {
$files = array_merge($files,pc_process_dir($subdirectory,$max_depth,$depth+1));
}
}
return $files;
}