<?php
$files = Array(); // to hold file names
$tmp = glob("*"); // grabs all file/directories in current directory
$t2 = preg_split("/\//", $_SERVER['PHP_SELF']);
$currFile = $t2[count($t2)-1]; // grabs just the filename and no path
// grab all of the files and leave behind the directories
foreach ($tmp as $f) {
if (!is_dir($f)) { $files[] = $f; }
}
// get index of current page in array
$key = array_search($currFile, $files);
// output previous link if there is a previous
if (array_key_exists($key-1, $files)) {
echo "<a href='". $files[$key-1] ."'>Previous</a> ";
}
// output next link if exist
if (array_key_exists($key+1, $files)) {
echo "<a href='". $files[$key+1] ."'>Next</a> ";
}
?>