开发者

How to put the files of a folder in an array?

开发者 https://www.devze.com 2023-04-10 03:14 出处:网络
In a folder \"images\" I have a thousand xml files.Those filenames I want them to be insert into 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消