I have a directory of images on a server that customers have uploaded. I need to be able to get all files that match a certain string or item code and put them inside an array. Filenames and extensions can always vary but each file will always have an 8 digit item code in the filename. So for instance say in my directory i have:
/images/
62115465.jpg
62115465-02.jpg
62115465-07.jpg
13452766.png
56773392.jpeg
56773392-avatar.jpg
I want to be able to pull out all the files that match the 8 digit item code so:
//all images that have 62115465 in the file name would give me
62115465.jpg
62115465-02.jpg
62115465-07.jpg
//or all images that have 56773392 in the file name would give me
56773392.jpeg
56773392-avatar.jpg
and then want them in an array like so:
$all_files = array(
'62115465.jpg',
'62115465-02.jpg',
'62115465-07.jpg'
);
I tried using the glob() function as below which can match some files like the 62115465.jpg but doesnt pick up the 2 other files with the -02 and -07 tags
$files = glob('62115465.'.*');
.?$files = glob('62115465*.*');it will match anything starting with the number and with any ext.