I am using this short script to list images within a specific folder
$dirname = "images/gallery/Project 1/";
$images = glob($dirname."*.jpg");
foreach($images as $imagesm) {
print "$imagesm";
}
However, in folder gallery I have 3 folders (Project 1, Project 2, Project 3) and I want to make the script go through each folder automatically and print the images from them.
For example:
Project 1 - image 1 - image 2 - image 3
Project 2 - image 1 - image 2 - image 3
Project 3 - image 1 - image 2 - image 3
I know that I can just copy the script for each folder, but want it to happen automatically as I might add a folder Project 4 in the future
I guess I will just need to loop through the folders, but no idea how to do it. Tried to do it this way, but it didnt work either
$dir = "images/gallery/";
$cdir = scandir($dir);
foreach ($cdir as $dirname)
{
$newdir="images/gallery/$dirname";
$images = glob($newdir."*.jpg");
foreach($images as $imagesm) {
print "$imagesm";
}
}
Here is the final working code if someone is interested
$mydir = 'images/gallery';
$subdirs = array_filter(glob($mydir . '/*'), 'is_dir');
foreach($subdirs as $dir){
echo '<b>'.basename($dir).'</b><br>';
$images = glob($dir . '/*.jpg');
foreach($images as $image)
{
echo basename($image).'<br/>';
}
}