Currently I have the code below what would be the best way for me to be able to set the flags in the code below so I can use ::SKIP_DOTS
?
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;?>
Setting RecursiveDirectoryIterator::SKIP_DOTS
as an option (in the second parameter) to new RecursiveDirectoryIterator()
should be sufficient to work with your current code.
With PHP 5.3+, you may alternatively declare the RecursiveDirectoryIterator
as its own variable then call a method on that variable:
$iterator = new RecursiveDirectoryIterator($folder);
$iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
// Still need to pass $iterator to a RecursiveIteratorIterator...
setFlags()
is a method inherited from the FilesystemIterator
base class.
But since you are already using the template formatting foreach: / endforeach;
style, it makes sense to just do it in the nested declaration rather than using additional variables.
<!-- 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): ?>
<!-------------------------------------------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With