I have been trying to ask this question i several forums in my country "Norway", and it seems like nobody can help me, so i really hope someone can do it here.
I have a script, that i really like a lot, and that I want to use, but pagination is missing Sad
This is a image gallery script, and the way it works is that it pics up the images that is in the folder that the php file is stored in.
It create thumbnails for me automaticly, and crop them to perfect squares, whitout ditorting the image (something that i really like)
It sorts the images, so the latest image uploaded to the folder comes first, no matter what the name of the image is.
I can conrol collums... Basicly i like the script the way it is, and dont want any of the functions it haves to ba taken away.
This is how it looks like now:
http://www.cloevvold-photo.com/TEST_SCRIPTS/test/landskap/
But I cant controll rows.. witch is bad.. I would like to be able to control how many rows i want to use, and when the collums and rows are filled in, i would like the pagination to appear below the thumbnails..
I have seen a video about pagination.. and i really like the way that the pagination is there.. but its require a database..
The file I have now, is only 1 file, and requiers no database, and I would really like it to stay that way.
Is it possible to get the same kind of Pagination that you see in this video:
http://www.sampsonvideos.com/videos/PHP/PHP_Pagination/
whitout the use of a database, and that it still is the 1 file I have??
I really hope that someone here cab help me..Huh
This is the script I have:
<?php
$thumb_size = 100;
$columns = 5;
$rows = 1;
function resizeImage($source) {
global $thumb_size;
$size = getimagesize($source);
$width = $size[0];
$height = $size[1];
if($width > $height) {
$x = ceil(($width - $height) / 2 );
$width = $height;
} elseif($height > $width) {
$y = ceil(($height - $width) / 2);
$height = $width;
}
$new_im = imagecreatetruecolor($thumb_size,$thumb_size);
$im = imagecreatefromjpeg($source);
imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height);
return $new_im;
}
function generateThumbnails(){
// Open the actual directory
if ($handle = opendir(".")) {
// Read all file from the actual directory
while ($file = readdir($handle)) {
// Check whether tha actual item is a valid file
if (is_file($file)){
// Check whether the actual image is a thumbnail
if (strpos($file,'_th.jpg')){ $isThumb = true; } else { $isThumb = false; }
if (!$isThumb) {
// Process the file string
$dirName = substr($file,0,strpos($file,basename($file)));
if (strlen($dirName) < 1) $dirName = '.';
$fileName = basename($file);
$fileMain = substr($fileName,0,strrpos($fileName,'.'));
$extName = substr($fileName,strrpos($fileName,'.'),strlen($fileName)-strrpos($fileName,'.'));
// Check if the actual file is a jpeg image
if (($extName == '.jpg') || ($extName == '.jpeg')){
$thmbFile = $dirName.'/'.$fileMain.'_th.jpg';
// If a thumbnail dosn't exists tahn create a new one
if (!file_exists($thmbFile)){
imagejpeg(resizeImage($file),$thmbFile,80);
}
}
}
}
}
}
}
function getNormalImage($file){
$base = substr($file,0,strrpos($file,'_th.jpg'));
if (file_exists($base.'.jpg')) return $base.'.jpg';
elseif (file_exists($base.'.jpeg')) return $base.'.jpeg';
else return "";
}
function displayPhotos(){
global $columns;
generateThumbnails();
// Open the actual directory
if ($handle = opendir(".")) {
// Read all file from the actual directory
while ($file = readdir($handle)) {
// Check whether tha actual item is a valid file
if (is_file($file)){
// Check whether the actual image is a thumbnail
if (strpos($file,'_th.jpg')){
$fil = ereg_replace("_th.jpg",".jpg",$file);
$time = filemtime($fil);
$normal = getNormalImage($file);
$bilde[$time] = $file;
}
}
}
if (isset($bilde)) {
$count = count($bilde,1);
display($bilde,$count);
} else { echo "Det er desverre ikke noen bilder her!"; }
}
}
function display($file,$count) {
global $columns,$rows;
$max_site = ceil(($columns * $rows) / $count);
krsort($file);
$act = 0;
foreach ($file as $time => $fil) {
$i++;
++$act;
if ($act > $columns) {
echo '</tr><tr><td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>';
$act = 1;
} else {
echo '<td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cecilie Løvvold Photography</title>
<link href="../style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div class="caption">Landskap</div>
<table align="center"><tr>
<?php displayPhotos(); ?>
</table>
</div>
</body>