RecursiveDirectoryIterator Removing Point Folders

I currently have the code below, what would be the best way for me to set the flags in the code below so that I can use ::SKIP_DOTS?

The code:

  $folder = 'images/banner_img';?>

    <?php foreach( new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder)) as $filename): ?>
      <?php $fileTypes = array("db"); 
            $fileType  = pathinfo($filename,PATHINFO_EXTENSION);

            if(!in_array(strtolower($fileType), $fileTypes)):?>


         <img src="<?php echo $filename; ?>" alt="" title="" data-thumb="<?php echo $filename;?>" />

       <?php endif;?>

    <?php endforeach;?>
+4
source share
1 answer

Setting RecursiveDirectoryIterator::SKIP_DOTS as an option (in the second parameter) before new RecursiveDirectoryIterator()should be sufficient to work with your current code.

With PHP 5.3+, you can also declare RecursiveDirectoryIteratoras your own variable, then call the method for this variable:

$iterator = new RecursiveDirectoryIterator($folder);
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
// Still need to pass $iterator to a RecursiveIteratorIterator...

setFlags()- This is a method inherited from the base classFilesystemIterator .

foreach: / endforeach;, , .

<!-- Instead, stick with your current iterator declaration and -->
<!-- add RecursiveDirectoryIterator::SKIP_DOTS as the 2nd param to its constructor -->
<?php foreach( new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS)) as $filename): ?>
<!-------------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
+5

All Articles