johanafm;10928775 wrote:Semi working script to do what you ask. scandir includes directories, so check for is_file will be needed. Even if you only keep files in your directory, both . and .. are always included.
Also, non image files should probably be detected.
And finally, some kind of end case handling. i.e. what to do if you're viewing the first or last file.
$dirname = './images/';
$files = scandir($dirname);
$key = array_search(basename($_GET['currentFile']), $files);
if (isset($_GET['previous']))
$showFile = $files[$key - 1];
else if (isset($_GET['next']))
$showFile = $files[$key + 1];
else $showFile = $files[2];
echo '<img src="/images/'.$showFile.'" alt=""/><br/>';
echo '<a href="?previous=1&currentFile='.urlencode($dirname.$showFile).'">Previous</a><br/>';
echo '<a href="?next=1&currentFile='.urlencode($dirname.$showFile).'">Next</a><br/>';
fm you are in the house...worked so good it made me want to curse!
just one thing though mr senior member in the house with the extra props!!!
i get this above the first image
Notice: Undefined index: currentFile in C:\vhosts\zandiconstruction\phpBuiildersPhotoTest.php on line 11
then everything is fine and dandy do i have to declare currentFile in order for that not to show?
here is my code
<!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>
</head>
<body>
<?php
$dirname = 'phpBuildersPhotoTest/';
$files = scandir($dirname);
$key = array_search(basename($_GET['currentFile']), $files);
if (isset($GET['previous']))
$showFile = $files[$key - 1];
else if (isset($GET['next']))
$showFile = $files[$key + 1];
else $showFile = $files[2];
echo '<img src="phpBuildersPhotoTest/'.$showFile.'" alt=""/><br/>';
echo '<a href="?previous=1&currentFile='.urlencode($dirname.$showFile).'">Previous</a><br/>';
echo '<a href="?next=1&currentFile='.urlencode($dirname.$showFile).'">Next</a><br/>';
?>
</body>
god knows thanks again for the code....saved so much time,,,,,boy i need to work on my php:eek: