Using the RecursiveDirectoryIterator
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/6218145/displaying-folders-and-making-links-of-those-folders">Displaying folders and making links of those folders</a>  </p>
</blockquote>



<p>I'm trying to create a simple file browser using the RecursiveDirectoryIterator but can't seem to figure it out... Any help please?</p>

<pre><code>$cwd = '/path/to/somewhere';
if(isset($_GET['path']) &amp;&amp; is_dir($cwd.$_GET['path'])) {
    $cwd .= $_GET['path'];
}

$dir = new RecursiveDirectoryIterator($cwd);
$iter = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST);
while($iter-&gt;valid()) {
    // skip unwanted directories
    if(!$iter-&gt;isDot()) {
        if($iter-&gt;isDir()) {
            // output linked directory along with the number of files contained within
            // for example: some_folder (13)
        } else {
            // output direct link to file
        }
    }
    $iter-&gt;next();
}
</code></pre>

<p>Not sure if this is the best approach, but I'm under the impression that the RecursiveDirectoryIterator is faster than both the opendir() and glob() methods.</p>
