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().
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With