View Single Post
Old 02-08-2008, 06:32 PM   #2 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

An example which uses a directory of images is given below. The folder structure is such that we have an images folder and within that a thumbs folder. Filenames match between the folders representing a thumbnail and full-sized version of the same image. It's up to you to create the thumbnails however you like.

PHP Code:
<?php

include('pagination.php');
$p = (isset($_GET['p']) AND ctype_digit($_GET['p']) AND (int) $_GET['p'] > 0
   ? (int) 
$_GET['p'
   : 
1;
$max 10;

// Create the object and set some basic values.
$pagination = new pagination();
$pagination->setMax($max);

// Set up some directory variables 
$dir    dirname(__FILE__).'/images/';
$webdir 'images/';
$thdir  'images/thumbs/';

// Grab all of the images 
$images glob($dir.'*.jpg');

// Set up pagination variables
$totPages  $pagination->getPages($images);
$first     $pagination->setPage($p);
$page      $pagination->getCurrentPage();

// Only select the portion of the images array 
// that represents our page
$exResults array_slice($images$first$max);

// Make links spaced a bit
echo '
<style type="text/css">
a { margin: 0 2px 0 0; }
</style>'
;

// Start pagination display
printf('Page: %d of %d | '$page[0], $page[1]);
$pagination->checkLink($p 1) AND printf('<a href="?p=%d">Previous Page</a>'$p 1);
foreach (
$totPages as $pageNumber)
{
    
$tpl = ($pageNumber == $p)
         ? 
'<a href="?p=%1$d">%1$d</a>'
         
'<a href="?p=%1$d"><strong>%1$d</strong></a>';
    
printf($tpl$pageNumber);
}
$pagination->checkLink($p 1) AND printf('<a href="?p=%d">Next Page</a>'$p 1);

// Display current page of images 
echo '<hr><div class="images">';
foreach(
$exResults as $image)
{
    
$image str_replace($dir$webdir$image);
    
$thumb str_replace($webdir$thdir$image);
    
printf('<a href="%s" style="margin: 0 5px 5px 0;"><img src="%s" alt="%s"></a>',
           
$image$thumbbasename($image));
}
echo 
'</div>';
It's just a very quick example essentially ported over from the MySQL example posted above. Don't shoot me if it doesn't work!
Salathe is offline  
Reply With Quote
The Following 3 Users Say Thank You to Salathe For This Useful Post:
Alan @ CIT (02-08-2008), codefreek (10-31-2008), Tanax (02-08-2008)