【发布时间】:2012-01-22 09:27:06
【问题描述】:
可能重复:
PHP list of specific files in a directory
use php scandir($dir) and get only images!
所以现在我有一个目录,我得到一个文件列表
$dir_f = "whatever/random/";
$files = scandir($dir_f);
然而,它会检索目录中的每个文件。我如何以最有效的方式仅检索具有特定扩展名(例如 .ini)的文件。
【问题讨论】:
-
有几十个问题问同样的问题。 Please do research before asking questions.
-
使用
scandir -
//path to directory to scan $directory = "../file/";//get all image files with a .text extension.$images = glob($directory . "*.text ");//print each file nameforeach($images as $image){echo $image;} -
我认为
glob会比scandir更好。 -
us3.php.net/manual/en/function.glob.php
glob("*.txt")
标签: php filesystems