Heres an example - from the php manual.
// Read Directory Function
function listImages($dirname=".") {
$ext = array("jpg", "png", "jpeg", "gif");
$files = array();
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
for($i=0;$i<sizeof($ext);$i++){
if(strstr($file, ".".$ext[$i])){
$files[] = $file;
}
}
}
closedir($handle);
}
return($files);
}
$imageFiles = listImages('/full_image_directory_path/');
print_r($imageFiles);
So first thing is to get the list of files.
I personally would then save them in a session variable - so that I dont need to read the directory again.
Then create a currentImage pointer session variable - to keep track of where the current user is in the list of images.
Then have a some code which creates the php page that displays the image and the back and forward button.
The back and forward button should reload the same page but have a URL currentImage variable - which is the Array Key for the currentImage.
Don't forget to do some validation on the url variable! and check that the back and forward buttons are needed!