".") && ($file <> "..")) { $filearray[] = $file; } } sort($filearray); foreach($filearray as &$file){ $ext = substr($file, strlen($file) - 3); if ($ext == "jpg" || $ext == "png" || $ext == "gif") { // add one to the count $count++; // we found the image they wanted! if ($count == $cur) { $cur_img = "$gid/$file"; } } // if we find a copy.txt file, then replace the nis america copyright if ($file == "copy.txt") { $crfile = "$gid/$file"; $crh = fopen($crfile, 'r'); $copyright = fread($crh, filesize($crfile)); fclose($crh); } } } if ($count == 0) { // if we didn't find anything, just display the 404 image and set all of the other crap to 0 $cur_img = "http://nisamerica.com/img/404.png"; $prev = 0; $next = 0; } elseif ($count == 1) { // if this is the only other image, then don't bother with previous and next buttons $prev = 0; $next = 0; } else { // set our next and prev indexes and make sure they're IN BOUNDS $prev = $cur - 1; $next = $cur + 1; if ($prev < 1) { $prev = $count; // go to the end } if ($next > $count) { $next = 1; // loop back to the start } } ?> NISA Online Store - Product Images