I have a folder named hemlata993. So the structure of the folder is:
hemlata993 - It has 4 folder named as folder1, folder2, folder3, folder4 Inside folder1 there are a couple of images and same goes for rest of the folders.
hemlata993>folder1>image1, image2 etc.
hemlata993>folder2>image22, image44 etc.
and so on..
My code:
$image = './userPosts/hemlata993';
if (is_dir($image)) {
if ($dh = opendir($image)) {
while (($file = readdir($dh)) !== false) {
echo $file. "</br>";
$imageInDir = $image.'/'.$file;
echo $imageInDir. "</br>";
$files = glob($imageInDir."*.*");
for ($i = 0; $i < count($files); $i++) {
$userImage = $files[$i];
$fin = $userImage[1];
echo $fin;
echo '<img src="'.$fin.'" width="100" height="100" alt="Random image" />' . "<br /><br />";
}
}
}
}
The output:
folder3
./userPosts/hemlata993/folder3
folder2
./userPosts/hemlata993/folder2
folder4
./userPosts/hemlata993/folder4
..
./userPosts/hemlata993/..
.
./userPosts/hemlata993/.
/Random image
folder1
./userPosts/hemlata993/folder1
Not sure what is this in the middle of output as it does not show any folder name at the end:
..
./userPosts/hemlata993/..
.
./userPosts/hemlata993/.
I am not sure but it is not printing the images inside the folder. How can I make it work? Also, where it says /Random image
that's the only image it displays and that's also without the picture (more like a square box that says alt value in it). Any help is appreciated of how to print all the images inside hierarchy of folders?