This is what i use:
$directory = ("../staticpath/" . $dynamicfolder . "/staticpath");
$handle=opendir($directory);
while (false !== ($file = readdir($handle))) {
// this line makes sure you dont list "." or ".."
if ($file != '.' && $file != '..' && $file != 'thumbs' && $file != 'lagtinn') { ?>
<font face="arial" size="-1"><b><? echo "$file"; ?></b></font><br>
<? }} closedir($handle); ?>
Now, ofcourse you can write whatever code you want instead of the font.
<a href="view.php?whichfile=<? echo $file; ?>"><? echo $file; ?></a>
<a href="view.php?whichfile=<? echo $file; ?>"><img src="paths/if/neccessary/<? echo $file; ?>"></a>
See? Just fool around with it, if you get any problems you know where to ask.
Yours Faithfully
Praxiz Consternatio