this is a code snippet to view the files in the directory. you can add $b to an array and check for .txt using ereg functions.
<?php
$dir="."; // directory to index
$a=opendir($dir);
while($b=readdir($a))
{
if(ereg(".",$b)) continue;
echo "<a href=$b>$b</a><br>";
}
closedir($a);
?>
nilesh.