// Use this for querystring to bypass cache every time... echo time(); ?>
// Functions similarly $.ready(); ?>
DEFINE('IMG_LIST_FILE', './picData.txt');
$pic = isset($_REQUEST['pic'])?$_REQUEST['pic']:"";
$mkthumbs = isset($_REQUEST['init']);
$picList = array();
$picElem = "";
$alt = "";
$ndx = 0;
$home = $_SERVER['PHP_SELF'];
if ($pic=="") {
// A specific filename was given. In this case, we'll be displaying the index page.
// During this process, we'll rebuild the temporary cached filename list file (which reflects the
// page that's about to be displayed) and write it out. It will be loaded for single pictures (see
// the "else" case, below), which is very rapid and will serve to let the next/previous buttons
// indicate the file spec that actually IS next or previous.
//echo "\n" . <-- if you want a logo that returns home.
echo "\n" .
"\n" .
"
Click to enlarge photos, click again to return to index.
\n";
echo "
"; // This last DIV serves as a container for ALL the thumbs.
foreach(glob("pics/*.[jJ][pP][gG]") as $file) {
if(($file=='.') || ($file=='..') || (stripos($file, 'IGNORE-THIS-FILE') > 0)) continue;
$alt = str_replace('pics/', '', $file);
$ndx++;
$picElem.array_push($picList, $file . "\n");
// Output each of the thumbs.
echo "
";
if ($mkthumbs) {
// From v1.17 forward, if you add "makethumbs" to the arguments, thumbnails will be forceably regenerated
// where necessary. Don't normally use this argument though, it prevents the thumbnails (although they may exist)
// from being cached.
echo "" .
"";
} else {
// We're not being asked check & create thumbnails. Simply reuse existing the existing thumbs. Added for v1.17.
$thumbSrc = substr(str_replace('pics/', 'pics/thumbs/', $file), 0, -4) . ".thumb.jpg"; // Gotta dance a little to get the right thumb SRC.
echo "";
}
echo "
\n";
}
// Every time the index is visited, recreate the pic list temp file that we built inside the loop, and rewrite the cache file.
file_put_contents(IMG_LIST_FILE, $picList);
// If recreation of missing thumbnails was requested, show a message and redirect back to self without the argument.
if($mkthumbs) { echo("\n"); }
} else {
// Just the one photo to display. Make it large.
// Reload the cached image list file. NOTE: If this is missing, don't display the next/prev buttons.
$cachedList = file_get_contents(IMG_LIST_FILE);
//echo("\n\n");
$cachedList = explode("\n", trim($cachedList)); // Split the cached file into an array.
// Be sure to trim() it, or you get an extra, empty line.
$ndx = 0;
$max = count($cachedList) - 1; // Total number of files in the list.
foreach($cachedList as $key=>$value) { // Loop to find the filespec the visitor asked for.
$prevPic = "$home";
$nextPic = "$home";
$withpath = "pics/" . $pic;
if($withpath == $value) { // We found an exact match for the filespec.
// Diagnostic for arrow key testing:
// echo("");
if($ndx==0) { $prevPic = $home . "?pic=" . substr($cachedList[$max], 5); } // Allow Prev on Pic 1 to jump to final pic.
if($ndx>0) { $prevPic = $home . "?pic=" . substr($cachedList[$ndx-1], 5); } // Locate the name of the prior image filespec, if any.
if($ndx<($max)) { $nextPic = $home . "?pic=" . substr($cachedList[$ndx+1], 5); } // Locate the name of the next image filespec, if any.
if($ndx==($max)) { $nextPic = $home . "?pic=" . substr($cachedList[0], 5); } // Allow Next on Pic(max) to jump to first pic.
break;
}
$ndx++; // We're off the next index.
// Will be length+1 after final iteration, but who cares.
}
// Now construct the IMG tag and its attributes for the specified pic.
$alt = str_replace('pics/', '', $pic);
echo <<< EOT
$alt
Click here for the full size image in a new tab/window.