I'm using the code below to return images in my images directory...you can see the live version at:
http://www.tacticalshooting.com/images/index.phpThe problem is that if you click any page other than the first one, it just reloads the first page...I'm missing something that allows the other pages to be viewed - do you see what it might be?
Code:
<?php
if(!isset($rows) || is_nan($rows)){
$rows=3;
}else if(!is_int($rows)){
$rows=round($rows);
}
if($rows<1){$rows=1;}
if(!isset($cols) || is_nan($cols)){
$cols=4;
}else if(!is_int($cols)){
$cols=round($cols);
}
if($cols<1){$cols=1;}
if(!isset($path)){
$thisdir=true;
$path='.';
}
if(!isset($page)){$page=1;
}
$dh=opendir($path);
while ($file = readdir($dh)) {
if (preg_match('/\.(jpg|gif|p
ng)$/i', $file)){
$files[] = $file;
}
}
$i = ($page-1)*$rows;
$pages = ceil(count($files) / ($rows*$cols));
echo "<table border=\"1\">\n";
echo " <tr>\n";
echo " <td colspan=\"$cols\" class=\"nav\">";
if($page>1){
echo "<a href=\"?page=" . ($page-1);
if($thisdir!=true){echo "&path=$path";}
echo "\">[Previous]</a>\n ";
}
echo " Page " . $page . "\n";
if($page<$pages){
echo "<a href=\"?page=" . ($page+1);
if($thisdir!=true){echo "&path=$path";}
echo "\">[Next]</a>\n ";
}
echo " </td>\n";
echo " </tr>\n";
for(;$i<($page-1)*$rows+$r
ows;$i++){
if($i*$cols>count($files))
{break;}
echo " <tr>\n";
for($j=0;$j<$cols;$j++){
if($i*$cols+$j >= count($files)){break;}
$size=getimagesize($path . "/" . $files[$i*$cols+$j]);
echo " <td>\n";
if($size[0]>450){
$size[0]=(int)($size[0]/4)
;
$size[1]=(int)($size[1]/4)
;
}else if($size[0]>250){
$size[0]=(int)($size[0]/2.
4);
$size[1]=(int)($size[1]/2.
4);
}
echo " <a href=\"" . $path . "/" . $files[$i*$cols+$j] . "\" target=\"new\">\n";
echo " <img border=\"0\" src=\"" . $path . "/" . $files[$i*$cols+$j] . "\" width=\"" . $size[0] . "\" height=\"" . $size[1] . "\" /><br />" . $files[$i*$cols+$j] . "\n </a>\n";
echo " </td>\n";
}
echo " </tr>\n";
}
echo " <tr>\n";
echo " <td colspan=\"$cols\" class=\"nav\">";
for($i=0;$i<$pages;$i++){
echo " ";
if($i+1!=$page){
echo "<a href=\"?page=". ($i+1);
if($thisdir!=true){echo "&path=$path";}
echo "\">";
}
echo "[" . ($i+1) . "]";
if($i+1!=$page){echo "</a>";}
echo " ";
}
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
?>
Start Free Trial