PHP分页:is_dir在循环读取readdir时截断图像

I just got pagination to work on my site, but I wanted to use a thumbnailer script that accepts a path, not a resource. This conflicts with how I pagination- using readdir to scan for a resource.

Right now I'm implementing a skip pattern I found online to keep track of images and their corresponding page numbers:

while ( $count <= $skip && ($file = readdir($handle)) !== false ) {
            if ( !is_dir($file))
                $count++;
        }

        $count = 0;

So,

Question 1) This method sets $count = 0 after it's run, so I don't see how it can be useful for the rest of the script.

Question 2) This part actually displays the correct images on page according to page number. I set $imagesPerPage = 4, so 4 should display on all pages. But, since I'm doing an !is_dir check, it's truncating those first two items (which are directories . and ..), but it's not refilling those spots with actual images (bec all pages except the last page should have 4 images on them...)

while ( $count++ < $imagesPerPage && ($file = readdir($handle)) !== false ) {
            if(!is_dir($file)) {
            $image = $imagePath . $file;
        ?>
            <a href="../templates/viewComic.php?image=<?php echo $image ?>"><img src="../scripts/thumbnailer2.php?img=<?php echo $image ?>" /></a>  

        <?php
            }   
        }

enter image description here

Question 3) How can I get the pages to begin on 1 instead of 0?

Any help in understanding would be appreciated!

1) This is resetting $count to 0 when the While is done with it.

2) You only want to increment $count if it's not a directory. You should put it inside the if(!is_dir($file)) section.

3) Initialize $count as 1 instead of 0.