You could probably read the directory and put all the file anmes into an array. then get the count of the array. This would be starting point for how many pages you will have.
I wrote this little bit of code which seems to work pretty good:
Change $recperpage to the number of images you want to display on one page
<?php
if (!isset($offset)) $offset = 0;
$recperpage = 5;
$dir = dir(".");
$dir->rewind();
while ($file = $dir->read()) {
if (is_file($file) && (($file != ".") && ($file != ".."))) {
$filelist[] = $file;
}
}
$count = sizeof($filelist);
for ($i=$offset; $i <= ($offset + $recperpage); $i++) {
sort($filelist);
print $filelist[$i] ."<br>";
}
$newoffset = ($offset + $recperpage);
$prevoffset = ($offset - $recperpage);
if ($offset < ($count - $recperpage)) {
printf('<a href="%s?offset=%s">Get next %s images</a><br>', $PHP_SELF, $newoffset, $recperpage);
}
if ($offset >= $recperpage) {
printf('<a href="%s?offset=%s">Get last %s images</a><br>', $PHP_SELF, $prevoffset, $recperpage);
}
?>