When using this php function readdir
, I'm wondering how can I exclude .htaccess files. However, the .htaccess file has no name. Just only the file type ".htaccess"
This is what I'm using right now trying to exclude that empty file name .htaccess...
if($file != "." || $file != ".." || $file != "index.php" || $file != ".htaccess" || $file != "")
However, it still doesn't exclude the empty file name .htaccess. Any ideas how I can approach this?
Your condition is incorrect, and will allow any value for $file
. You need:
if ($file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "")
You need to use &&
instead of ||
to mean "it is none of these files."
You could also write this as the following to be easier to extend in future:
$excludedFiles = array(".", "..", "index.php", ".htaccess", "");
if (!in_array($file, $excludedFiles)) { ... }