BreadBored
BreadBored

Reputation: 119

How do I display folder contents on webpage?

My question is a bit confusing, but I would like to display imgaes from a folder within a folder.

Here is my page I'm working on, see those blocks? I want to automatically take images from subfolders and list them in the style of those blocks. I can handle the styling part myself really, but is there an easy way to do this?

I'm very new to web automation and I have no idea how to go about this.

Upvotes: 0

Views: 1370

Answers (1)

Tateyaku
Tateyaku

Reputation: 154

php has a read directory class built in.

<?php

if ($handle = opendir('/path/to/files')) {
    echo "Directory handle: $handle\n";
    echo "Entries:\n";

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

    /* This is the WRONG way to loop over the directory. */
    while ($entry = readdir($handle)) {
        echo "$entry\n";
    }

    closedir($handle);
}
?>

Upvotes: 1

Related Questions