views:

45

answers:

2

I have this PHP script which i'm grabbing images from a directory and displaying them. The directory only has 4 image files in it and yet there are 6 li's. In firebug the images just have the paths 'Images/uploaded/.' and 'Images/uploaded/..'

Are there hidden files that this script is grabbing but not displaying correctly?

 <?php 

        $dir = 'Images/uploaded/';
        if($handle = opendir($dir)) {
            while(false !== ($file = readdir($handle))) {
                echo "<li><img class=\"thumb\" src=\"".$dir.$file."\" /></li>";
            }
        }

        closedir($handle);
    ?>
A: 

Your test for . or .. fails... example: You load '.' and your test says:

if('." is not "." OR its not "..") 

change this conditional to && (and).

Erik
Catfish
When you read a directory, two of the listings you get are '.' (current directory) and '..' (up one directory) - standard unix.
Erik
I guess that's what ignacio was trying to explain but i didn't understand. Thank you.
Catfish
A: 

Those are the entries for "current directory" and "parent directory, respectively. Just filter them out.

Ignacio Vazquez-Abrams