Introduction: My website IMG has images such as 1.jpg, JPG ,...... 、N.jpg1_1.gif1_2.gif1_3.gif ,...... 、N.gif: Create an index. php file under the images directory to display all images in the images directory by page. The following are my methods. I wonder if there is any better way. Haha... Create an index. php file under images in the image folder. The content is as follows:
<? PHP
Echo "<HTML> $ Page = $ _ Get ['page']; // obtain the current page number.
$ Max = 3; // you can specify the maximum number of images displayed on each page.
$ Handle = opendir ('./'); // Current Directory
While (false! ==( $ File = readdir ($ handle) {// traverse the directory where the PHP file is located
List ($ filesname, $ kzm) = explode (".", $ file); // get the extension
If ($ kzm = "GIF" or $ kzm = "jpg" or $ kzm = "jpg") {// file filtering
If (! Is_dir ('./'. $ file) {// folder Filtering
$ Array [] = $ file; // Save the qualified file name to an array
$ I ++; // record the total number of images
}
}
}
For ($ J = $ Max * $ page; $ j <($ Max * $ page + $ max) & $ j <$ I; ++ $ J) {// control the number of images displayed by cyclic conditions
Echo " <br>"; // output image Array
}
$ Previus_page = $ page-1;
$ Next_page = $ page + 1;
If ($ previus_page <0 ){
Echo "Previous Page ";
Echo "<a href =? Page = $ next_page> next page </a> ";
}
Else if ($ page <= $ I/$ max ){
Echo "<a href =? Page = $ previus_page> previous page </a> ";
Echo "<a href =? Page = $ next_page> next page </a> ";}
Else {
Echo "<a href =? Page = $ previus_page> previous page </a> ";
Echo "next page ";
}
Echo "</center> </body> ?>