I have the following PHP code that scans a directory and sub folders and lists all the PHP files in iframes.
I want to include all the PHP files from the directory except one, any instance of ‘index.php’.
I’ve tried adding:
if ($file != "." && $file != ".." && $file != 'index.php')
But it doesn’t work.
Here’s the full code:
<?php
$iterator = new RecursiveDirectoryIterator('work/');
foreach( new RecursiveIteratorIterator($iterator) as $filename => $cur) {
$file_info = pathinfo($filename);
if($file_info['extension'] === 'php') {
if ($file != "." && $file != ".." && $file != 'index.php')
echo
"<iframe width=420 height=150 frameborder=1 src='$filename'></iframe>";
}
}
?>
Thanks!
When you are doing it the iteratorish way, you might as well also use a filtering iterator.
RegexIteratorin particular can be useful, and avoid a few if checks in your case.I think testing for
.and..is redundant.