Allan
Allan

Reputation: 31

How to display file names from a folder

I'm using this script to display all the images in a folder, but I can't figure out how to get each image's file name to display underneath it. Any suggestions?

<?php

$dirname = "images";
$images = scandir($dirname);
$ignore = Array(".", "..", "otherfiletoignore");

foreach($images as $curimg){
    if (!in_array($curimg, $ignore)) {
        echo "<img src='images/$curimg' /><br />\n";
    }
} 
?>

Upvotes: 1

Views: 1135

Answers (2)

Milinda
Milinda

Reputation:

I think nickf's suggestion is the simplest thing you can do achieve what you want without any css or complex structure..

Upvotes: 0

nickf
nickf

Reputation: 545985

echo "<img src='images/$curimg' /><br />$curimg<br />\n";

Upvotes: 5

Related Questions