Get image name from folder in php
I have been trying to figure out a way to list all files contained within a directory. I'm not quite good enough with php to solve it on my own so hopefully someone here can help me out. I need a simple php script that will load all filenames contained within my images directory into an array. Any help would be greatly appreciated, thanks! asked Jan 13, 2010 at 20:13
0 Try glob Something like:
Anthony 35.6k24 gold badges93 silver badges159 bronze badges answered Jan 13, 2010 at 20:17
a.yastreba.yastreb 1,4931 gold badge10 silver badges11 bronze badges 4
Produces:
answered Jan 13, 2010 at 20:14
SampsonSampson 261k74 gold badges530 silver badges559 bronze badges 2 Either
Example
Or, to walk over the files in directory directly instead of getting an array, use
Example
To go into subdirectories as well, use RecursiveDirectoryIterator:
To list just the filenames (w\out directories), remove answered Jan 13, 2010 at 20:14
GordonGordon 307k72 gold badges526 silver badges551 bronze badges 2 You can also use the Standard PHP Library's
answered Jan 13, 2010 at 20:26
AnthonyAnthony 35.6k24 gold badges93 silver badges159 bronze badges 2 This will gives you all the files in links.
Taryn 237k55 gold badges362 silver badges402 bronze badges answered Oct 22, 2013 at 8:55
HardikHardik 1,27314 silver badges34 bronze badges Maybe this function can be useful in the future. You can manipulate the function if you need to echo things or want to do other stuff.
answered Aug 29, 2013 at 20:02
1 |