Check directory exists and if it doesnt choose an image
- by Andy
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.