1

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);
?>

2 Answers 2

3

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";
}
Sign up to request clarification or add additional context in comments.

Comments

1

You need to call readdir() within the loop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.