2010-07-30 67 views

回答

2

在UNIX系统中,如果文件名以点开头(.),则该文件将被隐藏。

在Windows中,如果文件具有隐藏属性,则隐藏文件。

您可以创建,检查的属性窗口下,因此下一个POSIX兼容的系统检查文件名功能:

function file_hidden($file) { 
    if (!file_exists($file)) 
     return false; 

    if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 
     $attributes = shell_exec('attrib ' . escapeshellarg($file)); 

     // Just get the attributes 
     $attributes = substr($attributes, 0, 12); 

     if ($attributes === 'File not fou') 
      return false; 

     // Return if hidden 
     return (strpos($attributes, 'H') !== false); 
    } else { 
     $basename = basename($file); 

     return ($basename[0] === '.'); 
    } 
} 
+0

它像是回应我的问题。但是您正在使用外部命令行应用来区分隐藏文件和非隐藏文件。这也意味着在Windows上没有这样做的PHP本地方式。 感谢您的回复。 – 2010-08-01 18:15:20

+0

@Darko Miletic:没有找到Windows中是否隐藏文件的Pure-PHP方式(至少不是没有非默认的PHP扩展)。您可以依靠'attrib'在每次安装Windows时都可用,上述解决方案将始终如一地运行。 – 2010-08-01 21:40:04