2
如何確定文件是否僅使用PHP函數標記爲隱藏?這尤其適用於Windows和Linux。跨操作系統的PHP和文件屬性
如何確定文件是否僅使用PHP函數標記爲隱藏?這尤其適用於Windows和Linux。跨操作系統的PHP和文件屬性
在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] === '.');
}
}
它像是迴應我的問題。但是您正在使用外部命令行應用來區分隱藏文件和非隱藏文件。這也意味着在Windows上沒有這樣做的PHP本地方式。 感謝您的回覆。 – 2010-08-01 18:15:20
@Darko Miletic:沒有找到Windows中是否隱藏文件的Pure-PHP方式(至少不是沒有非默認的PHP擴展)。您可以依靠'attrib'在每次安裝Windows時都可用,上述解決方案將始終如一地運行。 – 2010-08-01 21:40:04