Php read directory file

Posted by kwek-kwek on Stack Overflow See other posts from Stack Overflow or by kwek-kwek
Published on 2011-07-08T17:38:30Z Indexed on 2012/06/24 21:16 UTC
Read the original article Hit count: 144

Filed under:
|

I have a script that goes through a directory that has 3 images

$imglist='';
$img_folder = "path to my image";

//use the directory class
$imgs = dir($img_folder);

//read all files from the  directory, checks if are images and ads them to a list 
while ($file = $imgs->read()) {
  if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    $imglist .= "$file ";
} 
closedir($imgs->handle);

//put all images into an array
$imglist = explode(" ", $imglist);

//display image
foreach($imglist as $image) {
  echo '<img src="'.$img_folder.$image.'">';
}

but the problem that I am having is it display a 4th img with no image.. yet I only have 3 image in that folder.

© Stack Overflow or respective owner

Related posts about php

Related posts about php5