if folder exists with PHP
<p>I'd love some help....i'm not sure where to start in creating a script that searches for a folder in a directory and if it doesnt exist then it will simply move up one level (not keep going up till it finds one)</p>

<p>I am using this code to get a list of images.  But if this folder didn't exist i would want it to move up to its parent.</p>

<pre><code>$iterator = new DirectoryIterator("/home/domain.co.uk/public_html/assets/images/bg-images/{last_segment}"); foreach ($iterator as $fileinfo) {
    if ($fileinfo-&gt;isFile() &amp;&amp; !preg_match('/-c\.jpg$/', $fileinfo-&gt;getFilename())) {
        $bgimagearray[] = "'" . $fileinfo-&gt;getFilename() . "'";
    } }
</code></pre>
