Check directory exists and if it doesnt choose an image

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-03-27T16:35:14Z Indexed on 2010/03/27 16:43 UTC
Read the original article Hit count: 146

Filed under:

I have this code so far which perfectly but relies on there being a directory in place:

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

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...

Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about php