Check directory exists and if it doesnt choose an image
<p>I have this code so far which perfectly but relies on there being a directory in place:</p>

<pre><code>    $path = '/home/sites/therealbeercompany.co.uk/public_html/public/themes/trbc/images/backgrounds/'.$this-&gt;slug;
$bgimagearray = array();
$iterator = new DirectoryIterator($path);
foreach ($iterator as $fileinfo) {
    if ($fileinfo-&gt;isFile() &amp;&amp; !preg_match('\.jpg$/', $fileinfo-&gt;getFilename())) {
        $bgimagearray[] = "'" . $fileinfo-&gt;getFilename() . "'";
    }
}
</code></pre>

<p>I need to work in a bit at the top so that if the directory doesnt exist it defaults to the images sat in the root of the background directory...</p>

<p>Any help would be appreciated.  </p>
