I would really like it ... I don’t know where to start creating a script that looks for a folder in the directory, and if it does not exist, it will simply move one level (do not keep going until you find one)
I use this code to get a list of images. But if this folder does not exist, I would like it to move to its parent.
$iterator = new DirectoryIterator("/home/domain.co.uk/public_html/assets/images/bg-images/{last_segment}"); foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile() && !preg_match('/-c\.jpg$/', $fileinfo->getFilename())) {
$bgimagearray[] = "'" . $fileinfo->getFilename() . "'";
} }
source
share