Answer the question
In order to leave comments, you need to log in
How to find all files in a folder by pattern?
Pictures are stored in the folder template - [name-number.jpg]
number - a number from 0 to unknown It is
necessary in php to display all the pictures on the screen for a specific name
To be honest, I don’t even know where to start, I haven’t dealt with regular expressions yet.
As I understand it, you need to use a regular expression to search for images in a folder and display the search result in a php loop.
Answer the question
In order to leave comments, you need to log in
First scan the directory: scandir
Then iterate over the resulting array in foreach .
You can do it without regular expressions if you don't know them:
$fileName = 'name-23.jpg';
$fragments = explode( '-' , $fileName, 2 );
// в результате в $fragments[0] будет попадать `name`
Use shell tools quickly and conveniently:
$output = shell_exec("find /path/to/dir -iname filename* -exec basename {} \;");
$fileNames = explode("\n", $output);
array_pop($fileNames); //последний элемент будет пуская строка
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question