Thumbnail display and pagination/Script critique:
Posted: Thu Mar 03, 2005 4:19 pm
Hello.
I would love some feedback on the "thumbnail display" part of my gallery script... Any suggestions of ways to optimize the script (especially the part where I display the thumbnail images)...
If needed, I can post the config file and "larger image display" parts of my script.
This is the "thumbnail display" part of my gallery script:
Also, I am would love to paginate the thumbnails on the page... something really basic... for example:
<<prev ( [1][2][3] ) next>>
I have gotten the below script to display text and it will paginate the results, but I am not sure how to go about plugging it into my code:
Any help/comments/suggestions/tips would rock!
Thanks in advance!
Cheers,
Micky
I would love some feedback on the "thumbnail display" part of my gallery script... Any suggestions of ways to optimize the script (especially the part where I display the thumbnail images)...
If needed, I can post the config file and "larger image display" parts of my script.
This is the "thumbnail display" part of my gallery script:
Code: Select all
<?php
# Settings, look at config file for more info:
$biggy_display = $configї'big_path'];
$thumb_path = $_SERVERї'DOCUMENT_ROOT'].$configї'tn_path'];
$thumb_display = $configї'tn_path'];
$what_gal = $configї'gal_name'];
# Background color for your swf's:
$swfbkgrnd = '#9CA0AD';
# Put possible extensions into array "$files_of_type" for use in the "str_replace" function:
$files_of_type = array(".jpg", ".gif", ".png");
# Declare $thumbs and $biggy as arrays (Good practice):
$thumbs = array(); // Holds the thumbs.
$biggy = array(); // Holds the larger images.
$current_dir = opendir($thumb_path); // Look for picture files in directory and add them to array.
while ($file = readdir($current_dir)) {
# Check if it's a file, and it has a valid extension:
if(eregi("(\.jpg|\.gif|\.png)$", $file)) {
$thumbsї] = $file;
# Remove the "tn_" in name of thumbnails...
# ...This will create a "large-image" array...
# Large photos/folders are equal to thumbnail names without the tn_ at beginning of name...
$biggyї] = str_replace("tn_", "", $file);
}
}
closedir($current_dir);
# Natural Sort of thumbnail images:
natcasesort($thumbs); // Does not seem to sort the images, but when print out array the text is?
if($thumbs == null) {
die("There are no files in this directory!"); // If no thumbnail images were found, alert user.
} else {
# Count number of images in thumbnail array:
$numElements = count($thumbs);
for($counter=0; $counter < $numElements; $counter++) {
$big_folder = $biggy_display.str_replace($files_of_type, "", $biggyї$counter])."/"; // Var to hold possible path to folder.
$fldr = str_replace($files_of_type, "", $biggyї$counter]);
if(is_dir($big_folder)) {
echo '<a href="'.$_SERVERї"PHP_SELF"].'?display='.$what_gal.'&test='.$fldr.'" target="_self"><img src="'.$thumb_display.$thumbsї$counter].'" alt="'.$thumbsї$counter].'" title="'.$fldr.'" /></a>'."\n";
} else {
echo '<a href="'.$_SERVERї"PHP_SELF"].'?display='.$what_gal.'&image='.$counter.'" target="_self"><img src="'.$thumb_display.$thumbsї$counter].'" alt="'.$thumbsї$counter].'" title="'.$fldr.'" /></a>'."\n";
}
}
}
?><<prev ( [1][2][3] ) next>>
I have gotten the below script to display text and it will paginate the results, but I am not sure how to go about plugging it into my code:
Code: Select all
<?php
##### My attempt at pagination of thumbnails (Using the array $thumbs:
$thispage = $_SERVERї"PHP_SELF"].'?display='.$what_gal;
$num = count($thumbs); // number of items in list
$per_page = 2; // Number of items to show per page
$showeachside = 5; //**Number of items to show either side of selected page
if(empty($start)) { $start=0; } // Current start position
$max_pages = ceil($num / $per_page); // Number of pages
$cur = ceil($start / $per_page)+1; // Current page number
if(($start-$per_page) >= 0) {
$next = $start-$per_page;
?>
<a href="<?php print("$thispage".($next>0?("&start=").$next:""));?>"><<</a>
<?php
}
print($cur);
print($max_pages);
print($num);
if($start+$per_page<$num) {
?>
<a href="<?php print("$thispage&start=".max(0,$start+$per_page));?>">>></a>
<?php
}
for($x=$start; $x<min($num,($start+$per_page)+1); $x++) print($thumbsї$x]."<br />");
?>Thanks in advance!
Cheers,
Micky