I have an internal website that provides download links to various documents for training purposes. At this point its by department so one just navigates to the department and using php it creates links to the files in a directory.
I am trying to add a search function that will go through a directory(and subs) and find files with files names that contain a specified string.
I have tried many solutions to people asking the same question(they are everywhere, yes I have seen and tried them) on stackoverflow and cant seem to get it to work. :(
Specifically, I have found a particular example, posted here (not the accepted one) PHP scandir recursively
<?php
function rsearch($folder, $pattern) {
$dir = new RecursiveDirectoryIterator($folder);
$ite = new RecursiveIteratorIterator($dir);
$files = new RegexIterator($ite, $pattern, RegexIterator::MATCH);
foreach($files as $file) {
yield $file->getPathName();
}}
That I think should work, but I don't understand how to access the results.( I think I am calling correctly)
Can someone please demonstrate how to use this? I would greatly appreciate showing how to call and then access the result. For example if I wanted to find all files in $folder(and sub folders) that contain the string "apple" in the file name and list the path/name for matching files.
Thanks alot!