2

我正在尝试扫描图像文件夹,但是我一直看到 mac 创建的 ._ 文件

我正在使用这段代码:

   <?php
if ($handle = opendir('assets/automotive')) {
    $ignore = array( 'cgi-bin', '.', '..','._' );
    while (false !== ($file = readdir($handle))) {
        if ( !in_array($file,$ignore)) {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>

关于为什么的任何想法?我创建了一个覆盖它的忽略数组。

更新:仍然显示两者。

4

3 回答 3

7

我认为您想忽略任何以点 (.)开头的文件,而不仅仅是文件名。

<?php
if ($handle = opendir('assets/automotive')) {
    $ignore = array( 'cgi-bin', '.', '..','._' );
    while (false !== ($file = readdir($handle))) {
        if (!in_array($file,$ignore) and substr($file, 0, 1) != '.') {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
于 2011-03-29T20:12:48.327 回答
2

in_array() 接受两个参数:要查找的内容和要搜索的数组。您想要:

if ( !in_array($file, $ignore))
于 2011-03-29T20:08:02.143 回答
0

您正在检查in_array,但接下来的问题是:“是什么in_array”。

in_array 需要第二个参数,在这种情况下$file,要查找。你需要:

in_array($file,$ignore);
于 2011-03-29T20:08:24.847 回答