2010-07-30 69 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