[英]how to hide a file from readdir() php
My code loops through a directory and displays all the files and folders where I have a index.php file that I don't want to be displayed. 我的代码遍历目录,并显示所有我不想显示的index.php文件的文件和文件夹。
<?php
$directory = 'jocuri';
$row = 0;
if ($handle = opendir($directory.'/'))
{
echo '<table border="1">';
while ($cat = readdir($handle))
{
if ($cat != '.' && $cat != '..')
{
if($row==0) echo '<tr>';
echo '<td align="center">';
echo ' <a href="'.$directory.'/'.$cat.'" style="text-decoration:none">';
echo ' <img src="'.$directory.'/'.$cat.'/image.php" style="display:block" />'.str_replace('_', ' ', $cat);
echo ' </a>';
echo '</td>';
if($row == 2)
{
echo '</tr>';
$row = -1;
}
$row++;
}
}
echo '</table>';
}
?>
How can i achieve that? 我该如何实现?
Staying quick and dirty: 保持快速和肮脏:
if ($cat != '.'&&$cat != '..' && $cat != 'index.php'){ ... }
But I'll definitely move to some more consistent method like FilesystemIterator
or glob()
. 但是我一定会使用一些更一致的方法,例如
FilesystemIterator
或glob()
。
while($cat = readdir($handle)) {
if (in_array($cat, array('.', '..', 'index.php')))
continue;
// display the file here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.