Skip to content
Advertisement

how to display all images in a folder

I’m develop my websites and want to display all the images in a folder. I used the following code but occurred an error.

<?php 
    $sesi = Session::get('id'); 
    $gambar = glob('archive_gambar/formulir/pendaftaran/'.$sesi.'/*'); 
      for ($i=0; $i<count($gambar); $i++) 
      { 
        $single_image = $gambar[$i];
        ?>
        <img src="<?php echo $single_image; ?>" class="img-responsive" style="margin-left: auto;margin-right: auto; margin-top: auto;margin-bottom: auto;width:75%;" alt="Tri">
        <?php
      }
  ?>

there is no error, the number of images is the same, but the picture does not appear.. like this picture not appear

Advertisement

Answer

$dirname = "media/images/iconized/";
$images = glob($dirname."*.png");

foreach($images as $image) {
    echo '<img src="'.$image.'" /><br />';
}
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement