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);
setFlags()- This is a method inherited from the base classFilesystemIterator .
foreach: / endforeach;, , .
<?php foreach( new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::SKIP_DOTS)) as $filename): ?>