I been banging my head over this for sometimes now, But I cant get the result I am after, I was hoping someone can liberate me from the forever circle of mistakes..
function file_match($file_path, array $patterns) {
$files = array_diff(scandir($file_path), array('.', '..'));
foreach($files as $file) {
$full_path = $file_path . DIRECTORY_SEPARATOR . $file;
foreach($patterns as $pattern) {
if (is_file($full_path)) {
if (fnmatch(strtolower($pattern), $file)) {
echo $file;
echo "<br>";
}
} elseif (is_dir($full_path)) {
echo $file;
echo "<br>";
file_match($full_path, $pattern);
}
}
}
}
$file_path = 'X:/testfolder1/Monthly Files';
echo file_match($file_path, ['*.doc', '*.zip', '*.pdf]);
Expecting result:
Directory1
List of files resides inside this directory
Directory 2
List of files Resides inside this directory
etc
like:
This is what it should be: Monthly Files Test File Main 2.PDF Test File Main 1.doc January Files File January 1.PDF File January 2.zip February Files Files February 1.PDF Files February 2.PDF
etc