php - 用php忽略隐藏文件

标签 php arrays opendir

<分区>

我正在尝试扫描图像文件夹,但我一直看到 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);
}
?>

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

更新:仍然显示两者。

最佳答案

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

<?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);
}
?>

关于php - 用php忽略隐藏文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5478263/

相关文章:

php - 交响乐 2.5 : sql query with Where IN Clause using an array as a parameter

php - Codeigniter:foreach 方法或结果数组?? [模型+ View ]

ios - 在 swift 中创建一个带有 for 循环的字典

php - 如何将多个键和值推送到 php 数组中?

php - 我如何通过另一个相关表 Yii CDbCriteria 过滤查询?

php - Laravel .env 文件返回错误数据

arrays - 将函数放入元组会产生 "cannot convert value of type"错误

C opendir 按主机名

php - php中readdir()函数的返回值中的单点和双点是什么