PHP (Linux) all files beginning with ...

willsherwood
willsherwood used Ask the Experts™
on
I need to generate a loop to display all images that begin with a given base filename (which will have suffixes of various syntaxes, but the base that i give will be unique for this image grouping purpose).  The (foreach?) loop would iterate four times in the below case.
Please help me with the PHP wildcard directory search and ensuing loop to process the files

example directory contents:
100.jpg
100a.jpg
100b.jpg
100c.jpg

$directory_results_from_wildcard_search =
               directory_lookup_wildcard ($path_with_base_filename+"*"+".jpg");

//explode???  line by line???

foreach ($directory_results_from_wildcard_search)
{
 i can display image at a time here, i'm okay with this part
}

Open in new window


thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
maybe something like glob function? http://php.net/manual/en/function.glob.php
<?php
foreach (glob("$path_with_base_filename*.txt") as $file) {
    echo "$file\n";
}
?>

Author

Commented:
i read in the first reference that there may be a problem with # files.
this directory in this example has 4000 (!) files.
It's an inherited client site, so we have to live with the situation.
i'll give these a try.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
well, comment about large number of files was for numbers from 100000 in folder, 4k shouldn't be a problem.
Of course, you should give it a try, and think of other solution if you encounter "Allowed memory size" error

Author

Commented:
yes works fine,  many thanks

Author

Commented:
appreciated

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial