PHP可以列出文件名吗?

时间:2014-01-05 17:15:36

标签: php

目前我将这些文件放在一个文件夹中:

是否可以列出所有以 server_log 开头的文件并在屏幕上显示这些文件名?

2 个答案:

答案 0 :(得分:5)

使用glob()

$ListFile = glob("/path/server_log_*");
print_r($ListFile);

答案 1 :(得分:0)

是的,请查看this answer

$dir ="your path here";

$filetoread ="server_log";
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
           if (strpos($file,$filetoread) !== false)
            echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
        }
        closedir($dh);
    }
}