Code: Select all
<html>
<body>
<?php
$allowedExtensions = array('.jpg', '.jpeg', '.png', '.bmp');
$dir = "images/gage/";
$dh = opendir($dir);
$i=1;
while (($filename = readdir($dh)) !== false) {
if (is_file($dir.$filename)) {
$extension = strrchr($filename, '.');
if (in_array($extension, $allowedExtensions)) {
$image[$i]=$filename;
$i++;
}
}
}
$i++;
closedir($dh);
?>
<img src="<?= "$dir/$image[1]" ?>"><br>
<img src="<?= "$dir/$image[2]" ?>"><br>
<img src="<?= "$dir/$image[3]" ?>"><br>
<img src="<?= "$dir/$image[4]" ?>"><br>
<img src="<?= "$dir/$image[5]" ?>"><br>
</body>
</html>I notice when I look at the code thru my web browser it is saying the order of the images displayed is:
gage_2.jpg
gage_3.jpg
gage_4.jpg
gage_5.jpg
gage_1.jpg
If gage_1.jpg is the first image in the directory why does the code store gage_2.jpg in the $image[1]"?
Any other comments on this code are welcome.