Reputation: 37
The directories inside a gallery folder are dynamically created. And i am trying to access folders and corresponding images in it.As per now i accessed the folders but i am not getting images inside it.How to loop all images corressponding to a directory. Please help me with this issue to fix it
<?php
#default directory
$dir = '../gallery/';
$files1 = scandir($dir);
#open a gallery directory
if ($handle = opendir($dir)) {
#read all the directories inside a gallery folder
while($file = readdir($handle)){
if($file !== '.' && $file !== '..'){
#get all images inside variable $file
echo '<img src="../gallery/'.$file.'/" border="0" height="100" width="150"/>';
}
}
}
?>
Upvotes: 0
Views: 103
Reputation: 2874
foreach(glob("../gallery/".'*') as $filename) {
echo '<img src="../gallery/'.basename($filename).'/" border="0" height="100" width="150"/>';
}
Upvotes: 1