<?
$dir = "/pic/";
$realDir = $_SERVER["DOCUMENT_ROOT"] . $dir;
$webDir = $_SERVER["SERVER_NAME"] . $dir;
$allowExt = array("jpg");
// Open a known directory, and proceed to read its contents
if (is_dir($realDir))
{
if ($dh = opendir($realDir))
{
$fileArray = array();
while(($file = readdir($dh)) !== false)
{
$arr = explode (".", $file);
$extension = end($arr);
if(in_array($extension,$allowExt))
{
$fileArray[] = $file;
}
}
closedir($dh);
}
}
$antalImages = count($fileArray)/2;
$offset = (isset($_GET["offset"]) && $_GET["offset"]>0)?$_GET["offset"]:0;
$maxPictures = 10;
$kolonner = 2;
$maxLimit = $offset+$maxPictures;
if($antalImages > 0)
{
ksort($fileArray);
echo "<table id=\"centerTable\">\n";
echo "<tr>\n";
if($offset == 0)
echo "<td>Prev</td>\n";
else
echo "<td><a href=\"".$_SERVER["PHP_SELF"]."?offset=".($offset-10)."\">Prev</a></td>\n";
if($maxLimit>$antalImages)
echo "<td>Next</a></td>\n";
else
echo "<td><a href=\"".$_SERVER["PHP_SELF"]."?offset=".($offset+10)."\">Next</a></td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table id=\"centerTable\">\n";
echo "<tr>\n";
$i = 0;
for($i = $offset; $i < $offset+$maxPictures && $i < $antalImages; $i++)
{
if(!($i%$kolonner) && $i>0 && $i < $antalImages)
{
$tmp .= "</tr>\n<tr>\n";
}
$file = $fileArray[$i];
$tmp .= "<td><img src=\"
http://".$webDir."thumb_".$file."\"></td>\n"; }
for($i=0; $antalImages % $kolonner && $i<$kolonner-($antalImages % $kolonner); $i++)
{
$tmp .= "<td> </td>\n";
}
$tmp .= "</tr>\n</table>";
echo $tmp;
echo "<table id=\"centerTable\">\n";
echo "<tr>\n";
if($offset == 0)
echo "<td>Prev</td>\n";
else
echo "<td><a href=\"".$_SERVER["PHP_SELF"]."?offset=".($offset-10)."\">Prev</a></td>\n";
if($maxLimit>$antalImages)
echo "<td>Next</a></td>\n";
else
echo "<td><a href=\"".$_SERVER["PHP_SELF"]."?offset=".($offset+10)."\">Next</a></td>\n";
echo "</tr>\n";
echo "</table>\n";
}
else
{
echo "Vi har ikke uploadet nogle billeder endnu, de kommer...";
}
?>