0

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?

Kamerov
  • 109
  • 1
  • 4
  • 11
  • I'd like to apply what this article does to my scenario: https://stackoverflow.com/questions/25703618/get-all-photos-from-folder-and-paginate-with-php – Kamerov Jul 24 '18 at 06:15

1 Answers1

1

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

M Maavia
  • 340
  • 1
  • 9
  • Thanks for the response, can you give me an example of this code? I'm new to php – Kamerov Jul 24 '18 at 06:22
  • https://stackoverflow.com/questions/15774669/list-all-files-in-one-directory-php you can use above solution for getting all list of images file in an array – M Maavia Jul 24 '18 at 06:29