Thursday, February 17, 2011

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";
    }
} 
?>
From stackoverflow
  • echo "<img src='images/$curimg' /><br />$curimg<br />\n";
    
  • I think nickf's suggestion is the simplest thing you can do achieve what you want without any css or complex structure..

    Xenph Yan : If you aren't answering the question, then comment (when you have enough rep) all these extra answers pollute the question.
    MattSmith : It's a pain that you can't comment as soon as you join the site. If you ask a question you'll get enough rep pretty quickly though.
  • yuss!

    That's amazing, thanks nickf.

    I think my ultimate goal would be what you suggest, Milinda. Maybe when I have a firmer grasp on this whole thing (I'm very new to this game!)

    Thanks guys

0 comments:

Post a Comment