Is there a way to glob() only files?

后端 未结 5 1391
逝去的感伤
逝去的感伤 2020-12-30 21:34

I know that glob can look for all files or only all directories inside a folder :

echo \"All files:\\n\";
$all = glob(\"/*\");
var_dump($all);

echo \"Only d         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 21:48

    You can use GLOB_BRACE to match documents against a list of known file extensions:

    $files = glob("/path/to/directory/*.{jpg,gif,png,html,htm,php,ini}", GLOB_BRACE);
    

    see: http://www.electrictoolbox.com/php-glob-find-files/

提交回复
热议问题