So this is really more of a maths questions.
You will need to get the total count of the images, then divide that by the max number of images per page (make sure to ceil()
it).
You have now a max number of pages needed to view all of these images. What you need to do now is figure whether you want page=1/page=2 etc or as a start and end. Both are relatively easy, however, with the page you'd need to do
$page = (int)$_GET['page'];
$start = $page * $max_items_per_page;
$end = $start + $max_items_per_page;
This way it's probably saver. Also add extra code to make sure you're not out of bounds with the page requested.
Now it's a matter of getting an array of the files (I suggest you use glob()
) and use array_slice()
that from start to end.
Finally just have a previous/next page, or list all (or some) of the pages. Getting next and previous is as simple as adding/removing 1 to $page
, i.e. $next = $page + 1;
and $prev = $page-1;
. Again, for both of these, double check that you're not out of bounds. Probably best not to show next/previous if they are out of bounds.