Advertisement
Sparkster

Untitled

Jul 18th, 2013
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.     $imagetypes = array("image/jpeg");
  4.      
  5.     function getImages($folder) {
  6.             $images = array();
  7.             $directory = dir($folder);
  8.             while(($entry = $directory->read()) !== false) {
  9.                     if($entry == '.' || $entry == '..' || !strstr($entry, '.')) {
  10.                             continue;
  11.                     }
  12.                     $images[] = $entry;
  13.             }
  14.             return $images;
  15.     }
  16.      
  17.     if(isset($_GET['p'])) {
  18.         $pagination_start = intval($_GET['p']);
  19.     } else {
  20.         $pagination_start = 0;
  21.     }
  22.      
  23.     $images_per_page = 20;
  24.     $path = "tattoos";
  25.     $docroot = "$path";
  26.      
  27.     $images = getImages($path);
  28.     $images_start = $pagination_start * $images_per_page;
  29.     $images_end = $images_start + $images_per_page;
  30.     $pages_total = ceil(count($images) / $images_per_page);
  31.      
  32.     for($i = $images_start; $i < $images_end; $i++) {
  33.         $image = $images[$i];
  34.         echo "<a href='{$path}/{$image}'>";
  35.         $filename = explode('.', $image);
  36.         echo "<img src='{$path}/{$filename[0]}th.{$filename[1]}'>";
  37.         echo "</a>\n";    
  38.     }
  39.      
  40.     echo "<div class=\"pagination\"><ul>";
  41.     for($i = 0; $i < $pages_total; $i++) {
  42.         $j = $i + 1;
  43.         echo "<li><a href='index.php?page=gallery&gallery=tattoos&p={$i}'>{$j}</a></li>";
  44.     }
  45.     echo "</ul></div>";
  46.      
  47.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement