![]() |
How to get only images using scandir in PHP?
Is there any way to get only images with extensions jpeg, png, gif etc while using
Code:
$dir = '/tmp'; |
You can use glob
Code:
$images = glob('/tmp/*.{jpeg,gif,png}', GLOB_BRACE); |
I would loop through the files and look at their extensions:
Code:
$dir = '/tmp'; |
Here is a simple way to get only images. Works with PHP >= 5.2 version. The collection of extensions are in lowercase, so making the file extension in loop to lowercase make it case insensitive.
Code:
// image extensions |
| All times are GMT +8. The time now is 10:44 PM. |
Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.