如何使用PHP对图像进行分页?

I'm trying to paginate an arbitrary number of photos that I'm getting from a image directory onto my web page.

Here is my PHP script I'm running thus far:

<?php
    $dir = "images/";
    $counter = 1;
    if($opendir = opendir($dir)){
        //read directory
        while(($file = readdir($opendir)) !== FALSE){
            if($file != "." && $file != ".."){
                echo "<img src='$dir/$file' alt='Picture broken' style='border-style: solid;border-width: 2px;border-color: #4d94ff; margin: 5px'>";
                $counter++;
            }
        }
    }
    echo "<p>There are $counter images</p>";
?>

How do I get this to paginate automatically with 10 images on each page?

save all your images name of specific directory in a global array and paginate it with you own will :)