I'm looking for a routine that can be inserted into my php pages, that will read all the php files in the current folder... then echo a link to next file (sorted alphabetically from the present file), and a link to the previous file (also sorted alphabetical). Basically the type of sort really isn't that important, but am just trying to scroll from one page to the next through the entire folder. I've started with a basic script to list the directory, and I'm pretty much stumped after that. Any thoughts or assistance would be greatly appreciated. Thanks.
<< PREV NEXT >>
<?
$base = basename($_SERVER['PHP_SELF']);
echo $base;
echo "<br>";
$dirname = ".";
$dir = opendir($dirname);
while(false != ($file = readdir($dir)))
{
if (!preg_match('/(pdf|html|txt|bak|BAK|jpg|jpeg|lck|htaccess|htpasswd)/', $file))
{
if ($file != '.' &&
$file != '..' &&
$file != ".htaccess" &&
$file != "index.php" &&
$file != "finder.php")
$list[] = $file;
}
}
natcasesort($list);
foreach($list as $item) {
$itemfix = str_replace(" ","%20","$item");
echo("<a href='$itemfix'>$itemfix</a>");
echo "\n<br />";
}
?>