我有这个代码用于索引我网站上的目录和文件,但我需要排除一些文件(WHERE
或hidden_file.txt
)和一些扩展名(例如hidden_folder
)。我怎么能这样做?
这是代码,它有隐藏变量,但我真的不知道如何为我的目的更改它:
.php
答案 0 :(得分:0)
您的$hide
变量的唯一目的是隐藏以点开头的每个文件名:“。”和结果中的“..”和“.whatever”(当前文件夹,父文件夹和隐藏文件)。
// Gets each entry
while($entryName=readdir($myDirectory)) {
$ext = pathinfo($myDirectory . PATH_SEPARATOR . $entryName, PATHINFO_EXTENSION);
if(in_array($ext, array('php', 'secret', 'hidden'))){continue;} //Here the extension list you don't want to show
if(strpos(strtolower($entryName, 'hidden'))){continue;} //add as much rules as you want like so (this one means, if there is "hidden" in the filename, pass to the next file.
if(strpos(strtolower($entryName, 'secret'))){continue;}
$dirArray[]=$entryName; //if the filename has passed all rules it gets added to the list.
}