在使用这个php函数readdir时,我想知道如何排除.htaccess文件。但是,.htaccess文件没有名称。只是文件类型".htaccess“
这就是我现在使用的,试图排除空文件名.htaccess.
if($file != "." || $file != ".." || $file != "index.php" || $file != ".htaccess" || $file != "")但是,它仍然不排除空文件名.htaccess。有什么办法吗?
发布于 2013-11-17 14:16:41
您的条件是不正确的,并且允许$file的任何值。你需要:
if ($file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "")您需要使用&&而不是||来表示“这些文件都不是”。
您还可以将其写成以下内容,以便以后更容易扩展:
$excludedFiles = array(".", "..", "index.php", ".htaccess", "");
if (!in_array($file, $excludedFiles)) { ... }https://stackoverflow.com/questions/20031673
复制相似问题