tags:

views:

47

answers:

2

I have this script and when i try to run it, it just says waiting for localhost and never actually runs. If i go to my localhost i can run other files with no problem.

What's wrong with this script?

<?php 
    $dir = 'Images/uploaded/';
    if($handle = opendir($dir)) {
        $file = readdir($handle);

        while($file !== false) {
            echo "<li><img class=\"thumb\" src=\"".$dir.$file."\" /></li>";
        }
    }

    closedir($handle);
?>
+1  A: 

You need to call readdir() within the loop.

Ignacio Vazquez-Abrams
+3  A: 

You're not modifying $file inside the loop. $file never changes, and therefore you have an infinite loop.

From http://php.net/readdir:

/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
    echo "$file\n";
}
Dolph