Php MAC隐藏系统文件

Php MAC隐藏系统文件,php,macos,file,loops,Php,Macos,File,Loops,在使用此php代码遍历图像目录时,我需要过滤掉MAC dev计算机坚持创建的系统文件 首先,我只需要过滤掉 .DS_Store 文件,最近也出现了类似这样的文件: ._.DS_Store if ($handle = opendir($server_dir)) { //if we could open the directory... while (false !== ($entry = readdir($handle))) { //then loop throug

在使用此php代码遍历图像目录时,我需要过滤掉MAC dev计算机坚持创建的系统文件

首先,我只需要过滤掉

.DS_Store 
文件,最近也出现了类似这样的文件:

._.DS_Store


    if ($handle = opendir($server_dir)) { //if we could open the directory...
        while (false !== ($entry = readdir($handle))) { //then loop through it...
            if ( ($entry != ".") && ($entry != "..") && (strpos($entry, ".DS_Store") !== false) && (strpos($entry, "._.DS_Store") !== false) ) { //and skip the . and .. entities
                $m .= '
                '.$client_dir.$entry.'
                ';
            }            
        }
        closedir($handle);      
    }
    else {
        echo("Can't open $dir, does it exist? Does www-user have permission to read it?");
    }  
我是否需要过滤掉隐藏系统文件的任何其他名称,或者这两个文件是吗

有没有比我的处理方式更好的方法呢?

您可以替换这个:

 (strpos($entry, ".DS_Store") !== false) && (strpos($entry, "._.DS_Store") !== false)
据此:

 !stristr($entry, '.DS_Store')
还有,局部的,在一些地方见过。正如@deceze所说,unix系统中充满了
配置文件,这一切都取决于您使用的目录

或者更好的是,您可以将所有if语句替换为:

if(substr($entry, 0, 1)!='.')

可以有大量不同的隐藏文件,例如
.svn
.git
,以及上面的示例请尝试以下操作。。。它检查第一个字符是否为

if($entry[0] != '.'){
   // do something as its not a hidden file
}

“”,以点开头的文件,是UNIX系统对“隐藏”文件的长期约定。有很多是由各种各样的程序创建的。转到终端,玩
ls-a
。惯例是,除非你知道自己在做什么,否则要意识到它们并忽略它们。因此,忽略以
开头的所有文件

另请参见以下问题和答案: