Considering my working code for creating a gallery from a folder (g-images/) and using the file names for captions, how do I go about to exclude from such captions other file extensions other than *.jpg (i.e. *.png, *.gif)?
at the moment the only extension that gets removed is *.jpg. if it's any other extension it's kept as part of the caption for the image...
HELP, total newbie here :-)
<?php
$imglist = array();
$img_folder = "g-images/";
//use the directory class
$imgs = dir($img_folder);
//read all files from the directory, checks if are images and adds them to a list
while ($file = $imgs->read()) {
if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file)){
$imglist[] = $file;
}
}
closedir($imgs->handle);
//display image
foreach($imglist as $image) {
echo '<li><a href="'.$img_folder.$image.'" target="zoomed"><img src="timthumb.php?src='.$img_folder.$image.'&a=r&h=260" />';
echo '<p>'.str_replace('.jpg', ' ', str_replace('name', 'Name', $image)).'</p></a></li>';
}
?>