Ok Made Minor Change and now all hell has broke loose. Tried to make adjustment to eliminate the buttons using the pic as the button...
Using This Code:
<?php
session_start();
$dir = '/Test/images'; //<<<---- Path to your images,
if(!isset($_SESSION['images'])) { //If the image array IS NOT saved in sessions
if ($handle = opendir($dir)) { //Open the image directory.
while (false !== ($file = readdir($handle))) { //while there are files to read.
if($file != "." && $file != "..") { //if the file isn't current dir, or above dir.
$parts = explode('.',$file); //split the file on a period.
$c = count($parts); //count the parts array.
$ext = $parts[$c-1]; //ext will reside as the last value of the array.
if(strtolower($ext) == 'png' || strtolower($ext) == 'jpg' || strtolower($ext) == 'gif') { //if the ext is image type.
$images[] = $file; //save it to the image array.
}
}
}
closedir($handle); //close the directory.
}
$_SESSION['images'] = $images; //write the image array to a session variable.
} //this closes the if block, the above code will only run when the page is first open.
//Below is the displaying of the images, if you add images to the directory, you MUST close the browser window for
//this script to pick them up.
if(!isset($_SESSION['nextimage'])) { //if next image is NOT in the session array.
$next = $_SESSION['images'][1]; //next image will be the second image in the image array.
$current = $_SESSION['images'][0]; //current image will be the first image in the array.
}
else { //if next image is in the session array.
if(isset($_GET['next'])) { //and next is in the url bar.
$current = $_SESSION['nextimage']; //current image is changed to the one held in Sessions nextimage.
}
elseif(isset($_GET['prev'])) { //or if prev is in the url bar,
$current = $_SESSION['previousimage']; //we go to the previousimage in our sessions array.
}
}
$keys = array_keys($_SESSION['images'],$current); //find our array key of the current pic.
$n = $keys[0]; //the key will reside in the first place of the keys array.
$next = (array_key_exists($n+1,$_SESSION['images'])) ? $_SESSION['images'][$n+1] : $_SESSION['images'][0]; //if the next array key exists in the images array, set the next image, if it don't the first image is next.
$previous = (array_key_exists($n-1,$_SESSION['images'])) ? $_SESSION['images'][$n-1] : end($_SESSION['images']); //if the previous key exists in the images array, set the previous image to it, if it don't set previous to the last value of the image array.
$_SESSION['nextimage'] = $next; //write the next to the session array.
$_SESSION['previousimage'] = $previous; //write the previous to the session array.
$photo=$dir."/".$current;
echo "<a href=\"?next=1\"><img src=\"$photo\" alt=\"images\" /></a>"; // print the image element to the page.
?>
Displaying:
With this in the folder.
Any Thoughts?