Hi,
Somebody asked me to created a PHP image gallery that will read the images out of a directory and then create thumbnails for the gallery. There is one directory with thumnails, and one directory with fullsize images.
I read the file names out of the /thumb/ directory and insert each file name as a value into the thumbArray. From there I echo out the values in thumbnail src (<img src="<?php echo $thumbArray[$i]; ?>" />
) where $i is just a counter. So the thumbnail images are produced from the array but when you click on the thumbnail, it queries ?filename into the url. Using $_SERVER['QUERY_STRING'] I then read said query string and insert the query, (filename), into the the large <img src"<?php echo $_SERVER['QUERY_STRING']; ?>" />
. That is limited though. As I can now not read the array, as a reference point, and can no longer point forwards or backwards in the array.
Am I making more sense now?
Please help...
<?php
$i = 0;
/* Large file name and thumbnail file name must match */
/* Large image size = 480px x 300px */
echo '<img class="frameImg" src="images/large/'.$_SERVER['QUERY_STRING'].'" />';
?>
<p id="prevNext"><a href="#"><< Prev </a> || <a href="#"> Next >></a></p>
</div>
<div id="thumbs">
<ul>
<?php
/* Must change $dir to the full path of directory all the way from root /home/user/domain/images/thumb */
$dir = "*************************";
$dh = opendir($dir);
/* Thumbnail file name and large file name must match */
$thumbArray = array();
while (($file = readdir($dh)) !== false) {
if ($file != "." && $file != "..") {
$thumbArray[$i]=$file;
echo '<li id="'.$i.'"><a href="?'.$thumbArray[$i].'"><img src="images/thumb/'.$thumbArray[$i].'" alt="Alt for '.$thumbArray[$i].'" /></a></li>';
$i++;
}
}
closedir($dh);
?>