How to put the files of a folder in an array?
In a folder "images" I have a thousand xml files.Those filenames I want them to be insert into an array
$images = array('','');
Instead of writing them all by hand, and t开发者_Go百科his folder will be updated often, how can I do it automatically ?
Just exclude the .
and ..
entries if you don't want them:
$files = array_diff( scandir($dir), array('.','..') );
.
and ..
are always present in ALL directories ('current directory' and 'parent directory', respectively). You have to specifically filter them out. However, since you want only images, you could use something like glob()
to just fetch images using regular shell wildcard patterns, e.g.
$files = glob('*.jpg');
which would give you all the files whose names end in .jpg
.
精彩评论