问题
My code to get all images from a directory
$dirname = "uploads/";
$images = glob("{$dirname}*.png, {$dirname}*.jpeg, {$dirname}*.jpg, {$dirname}*.gif");
foreach($images as $image) {
echo "<img src='{$image}' class='files_main'>";
}
This works for one type of image but fails with multiple please give the syntax of defining multiple patterns in the glob().
回答1:
You can use the GLOB_BRACE
constant
GLOB_BRACE - Expands {a,b,c} to match 'a', 'b', or 'c'
e.g.
$dirname = 'uploads/';
glob("$dirname*.{png,jpeg,jpg,gif}", GLOB_BRACE);
See: http://php.net/manual/en/function.glob.php
来源:https://stackoverflow.com/questions/38899453/how-to-define-multiple-patterns-in-php-glob