Php scandir specific file type
Is there any way to get only images with extensions
Madan Sapkota 23.8k11 gold badges112 silver badges115 bronze badges asked Jul 12, 2010 at 7:19
You can use
If you need this to be case-insensitive, you could use a answered Jul 12, 2010 at 7:20
GordonGordon 307k72 gold badges525 silver badges550 bronze badges 4
The actual question was using scandir and the answers end up in glob. There is a huge difference in both where blob considerably heavy. The same filtering can be done with scandir using the following code:
I hope this would help somebody.
answered Jul 6, 2016 at 13:15
1 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.
I hope this is useful if you want case insensitive and image only extensions. answered Apr 29, 2015 at 15:39
Madan SapkotaMadan Sapkota 23.8k11 gold badges112 silver badges115 bronze badges 0 I would loop through the files and look at their extensions:
answered Jul 12, 2010 at 7:24
JosiahJosiah 4,6441 gold badge19 silver badges19 bronze badges You can search the resulting array afterward and discard files not matching your criteria.
answered Jul 12, 2010 at 7:20
BorealidBorealid 92.3k8 gold badges104 silver badges122 bronze badges If you would like to scan a directory and return filenames only you can use this:
answered Nov 18, 2017 at 17:17
Aaron OlinAaron Olin 3492 silver badges7 bronze badges 0 I wrote code reusing and putting together parts of the solutions above, in order to make it easier to understand and use:
answered Sep 18, 2021 at 21:39
2 |