这是隐藏PHP中的文件或文件夹的正确方法
我只是了解有关在PHP中使用课程的更多信息。我知道下面的代码是废话,我需要帮助。有人可以让我知道我是否朝着正确的方向前进?
while($entryName=readdir($myDirectory)) {
$type = array("index.php", "style.css", "sorttable.js", "host-img");
if($entryName != $type[0]){
if($entryName != $type[1]){
if($entryName != $type[2]){
if($entryName != $type[3]){
$dirArray[]=$entryName;
}
}
}
}
}
I am just learning more about using classes in PHP. I know the code below is crap has I need help. Can someone just let me know if I am going in the right direction?
while($entryName=readdir($myDirectory)) {
$type = array("index.php", "style.css", "sorttable.js", "host-img");
if($entryName != $type[0]){
if($entryName != $type[1]){
if($entryName != $type[2]){
if($entryName != $type[3]){
$dirArray[]=$entryName;
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎想要的是目录中没有四个特定名称之一的所有文件的列表。
大多数类似于您的代码更有效地做到这一点是
交替的,您可以在您提供的目录中分配循环(如书面,将在您提供的目录中包含文件和目录)
以添加后续:
@arkascha有一个使用的答案
array_filter
,虽然该示例只是array_diff
的实现,但该模式的动机是一个很好的一种:有时您可能会有时间想要排除更多的简单列表。例如,想象您要排除特定文件和所有目录是完全合理的。因此,您必须从列表中过滤目录。只是为了娱乐,我们也不要返回任何名称以。
开头的文件。What you seem to want is a list of all the files in your directory that do not have one of four specific names.
The code that most resembles yours that would do it more efficiently is
Alternately, you can dispense with the loop (as written, will include both files and directories in the directory you supply)
Edit to add for posterity:
@arkascha had an answer that used
array_filter
, and while that example was just an implementation ofarray_diff
, the motivation for that pattern is a good one: There may be times when you want to exclude more than just a simple list. It is entirely reasonable, for instance, to imagine you want to exclude specific files and all directories. So you have to filter directories from your list. And just for fun, let's also not return any file whose name begins with.
.您实际上想过滤输入:
输出是:
这种方法允许实现更复杂的过滤条件,而无需多次传递输入数据。例如,如果要根据文件名称扩展名或文件创建时间(即使是在文件内容上)添加另一个过滤条件。
You actually want to filter your input:
The output is:
Such approach allows to implement more complex filter conditions without having to pass over the input data multiple times. For example if you want to add another filter condition based on file name extensions or file creation time, even on file content.