I have written an image gallery script where the user can set a thumbnail folder variable and the script will pull up the images from that file and display the thumbnails on the page.
I've got it working fine but have trouble when I go to include the gallery onto my page that contains the usual header/content/footer.
Question: is it a bad idea to include the gallery script on a page or should it be it's own separate page with the header/footer included on it?
Brad.
image gallery include?
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
The main index page has include links to load any contents. If the user hits the "weddings" link then the index.php runs with the variable page="weddings.php" thus including the weddings.php file.
The gallery script is an include on the weddings.php file so I don't know if this is such a good idea...needed someone with good knowledge to evaluate it.
This is the gallery script:
Below is my index.php
Brad.
The gallery script is an include on the weddings.php file so I don't know if this is such a good idea...needed someone with good knowledge to evaluate it.
This is the gallery script:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Preview Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.imagebox {
margin: 2px;
float: left;
width: 120px;
height: 150px;
text-align: center;
}
.imagebox img {
margin-top: 5px;
border: 1px solid #9C9C9C;
}
.imagebox p {
clear: both;
margin-bottom: 5px;
font-size: 10px;
}
.imagebox table {
margin: 0px;
padding: 0px;
}
.imagebox td {
align: center;
text-align: center;
valign: middle;
height: 120px;
width: 120px;
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<?php
/*<USER DEFINED SETTINGS>
*******************************************************************************************/
$thumbs_folder = 'images/weddings/thumbnails';
$large_folder = 'images/weddings/large';
$gallery_name = 'My Preview Gallery';
$imagesperpage = 3;
$display_order = 'ascending'; // ascending, descending
$show_filenames = 'yes'; // 'no' if you don't wish to have filenames with images
/*<END USER DEFINED SETTINGS>
*******************************************************************************************/
/*<VARIABLES>
*******************************************************************************************/
$thumbs = array(); //array for images in thumbnails folder
$extentions = array('jpg','jpeg','JPG', 'JPEG'); //valid file extensions
//Paths
$site_path = $_SERVER['HTTP_HOST'] == 'localhost' ? 'G:/ApacheServer/printedvisions' : $_SERVER['DOCUMENT_ROOT'];
$thumbnailpath = $site_path . "/" . $thumbs_folder . "/";
$largepath = $site_path . "/" . $large_folder;
/*<END VARIABLES>
*******************************************************************************************/
//Retrieve images into an array if not already done so.
if(!isset($_GET['thumbs'])){
//Put the thumbnail images into an array
$dh = opendir($thumbnailpath);
while(($file = readdir($dh)) !== false) {
// check if it's a file, and it has a valid extension
if (is_file($thumbnailpath . $file) && in_array(substr($file, -3), $extentions)) {
// add image to array
$thumbs[] = $file;
}
}
closedir($dh);
// Sort the $thumbs array in the order chosen from the user settings
if (is_array($thumbs)) {
if ($display_order == "ascending") {
sort($thumbs);
} else {
rsort($thumbs);
}
}
}
// Get navpage number. If it doesn't exist set navpage = 1
if(!isset($_GET['navpage'])){
$navpage = 1;
} else { //If navpage is set
$navpage = $_GET['navpage'];
}
//Build Page Navigation Links
$totalimages = count($thumbs); //total number of images to display
$totalpages = ceil($totalimages/$imagesperpage);
$firstimage = ($navpage - 1) * $imagesperpage + 1;
//$lastimage = $navpage * $imagesperpage;
$lastimage = ($navpage * $imagesperpage) > $totalimages ? $totalimages : $navpage * $imagesperpage;
echo "page number: $navpage | images per page: $imagesperpage | total images: $totalimages | total pages: $totalpages<br>\n";
echo "Displaying $firstimage - $lastimage of $totalimages images<br>\n";
echo "Navigation: ";
if ( $totalpages <= 7 ) { //Don't need prev/next links if only 7 pages or less
for ( $p = 1; $p <= 7; $p++ ) {
if ( $p > $totalpages ) break; //Don't display more than $totalpages
if ( $p == $navpage ) {//Highlight the current navpage
echo "<b>$p</b>\n";
} else {
echo "<a href="$PHP_SELF?navpage=$p?">$p</a> \n";
}
}
} else {
}
//Display thumbnails
for ( $img = ($firstimage - 1); $img <= ($lastimage-1); $img++ ) {
echo "<div class="imagebox">\n";
echo "<table><tr><td>\n";
echo "<img src="$thumbs_folder/$thumbs[$img]"/>\n";
echo "</td></tr></table>\n";
//echo "<p>$thumbs[$img]</p>";
echo "</div>\n";
}
?>
</body>
</html>Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/styles/layout.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?
if (!isset($page)) {
$page = 'home.php'; //If no page is set for the contents then set it to home.php
}
?>
<div id="outer">
<div id="header">
<p>Header</p>
</div>
<div id="navbar">
<?php include 'navigation.php';?>
</div>
<div id="content">
<? include "$page";?>
</div>
<div id="footer">
<p>All content and images copyright © 1999-2004. All Rights Reserved.</p>
</div>
</div>
</body>
</html>