从文件夹加载项目的动态导航栏?

Alright, so i am really not sure if this is even possible. Here's what i want to do:

I have a folder called pages. It could look like:

index page2 page3

What i want to do is to list the files in a navigation bar using ul and il tags, like this:

ul

il a href="index" index

il a href="page2" page2

il a href="page2" page2

ul

And when i update the folder with a new file, i.e. page3, it would dynamically add that one too, like so:

il a href="page3" page3

I have no idea how to do this, i tried searching but without luck.

I know this is much to ask for, i just dont know where elso to ask.

Something like this:

foreach (glob("foldername/*") as $path) {
  $file = basename($path);
  echo "<li><a href="$path">$file</a></li>
";
}