JacobTheDev
JacobTheDev

Reputation: 18520

Embedding contents of a folder in a web page

I'm building a super simple CMS in PHP, and have what's probably a simple question...

I'm storing my news in .txt files (I know it should be a database, I'm just not focusing on that stuff for now...) and need to display these files on a page (news.php). It should basically print the contents of each file in reverse alphabetical order, for example:

Files:

12-11-11.txt
12-12-11.txt
12-13-11.txt
12-14-11.txt

Display:

Contents of 12-14-11.txt
Contents of 12-13-11.txt
Contents of 12-12-11.txt
Contents of 12-11-11.txt

I'd like to wrap each post in something like <div class="article"></div>.

I'm very new to PHP so a good code example would be lovely. I'm storing my files like this:

news page: /news.php
news files: /edit/news/

Upvotes: 0

Views: 45

Answers (1)

Michael Robinson
Michael Robinson

Reputation: 29498

foreach (glob("/edit/news/*.txt") as $filename) {
    echo "$filename size " . filesize($filename) . "\n";
}

Upvotes: 2

Related Questions