Galleri problemer
Hej Eksperter :)Har dette lille galleri-script:
<meta name="robots" content="all" />
<script type="text/javascript"> </script>
<style type="text/css">@import "main.css";</style>
</head>
<body>
<div id="container">
<div id="author">
<br class="clear" />
</div>
<div id="image">
<?
$settings["thumbsdir"] = "thumbs/"; // thumbnails directory with trailing slash
$settings["imagesperpage"] = 9; // must be an even number (pair numbers don't work well)
$settings["picsdir"] = "./galleri/"; // directory with pictures
$settings["types"] = array("jpg","jpe","jpeg","gif","png"); // allowed pictures
$dirhandle=@opendir($settings["picsdir"]);
$files = array();
while (($filename=@readdir($dirhandle))!==false)
{
$extension = strtolower(end(explode(".",$filename)));
if(in_array($extension,$settings["types"]))
{
$files[]=$filename;
// Create thumbnail, if no thumbnail exists
if(!file_exists($settings["picsdir"].$settings["thumbsdir"].$filename))
{
echo "DEBUG: THUMB MANGLER - " . $filename . "<br>";
echo "DEBUG - TYPE: " . $extension . "<br>";
switch($extension)
{
case "jpg":
case "jpeg":
case "jpe":
$srcimg = imagecreatefromjpeg($settings["picsdir"].$filename);
break;
case "gif":
$srcimg = imagecreatefromgif($settings["picsdir"].$filename);
break;
case "png":
$srcimg = imagecreatefrompng($settings["picsdir"].$filename);
break;
}
$width=imagesx($srcimg);
$height=imagesy($srcimg);
$thumbw=$width/10;
$thumbh=$height/10;
$dstimg = imagecreatetruecolor($thumbw,$thumbh);
imagecopyresampled($dstimg,$srcimg,0,0,0,0,$thumbw,$thumbh,$width,$height);
switch($extension)
{
case "jpg":
case "jpeg":
case "jpe":
imagejpeg($dstimg,$settings["picsdir"].$settings["thumbsdir"].$filename,80);
break;
case "gif":
imagegif($dstimg,$settings["picsdir"].$settings["thumbsdir"].$filename);
break;
case "png":
imagepng($dstimg,$settings["picsdir"].$settings["thumbsdir"].$filename);
break;
}
}
}
}
sort($files);
if (isset($_GET["image"]))
$key=array_search($_GET["image"],$files);
else
$key=0;
list($width,$height)=getimagesize($settings["picsdir"].$files[$key]);
echo '<img src="',$settings["picsdir"].$files[$key],'" width="466px" height="349px" alt="',$settings["picsdir"].$files[$key],'" /><br />';
?>
</div>
<div id="position">
<?
$totalfiles=count($files);
echo '<span>',$key+1,'/',$totalfiles,'</span>';
?>
</div>
<div id="thumbnails">
<?
$halfperpage=floor($settings["imagesperpage"]/2);
if ($key<$halfperpage)
{
$start=0;
$end=$settings["imagesperpage"]-1;
}
elseif ($key+$halfperpage>$totalfiles-1)
{
$start=$totalfiles-$settings["imagesperpage"];
$end=$totalfiles-1;
}
else
{
$start=$key-$halfperpage;
$end=$key+$halfperpage;
}
for ($i=$start;$i<=$end;$i++)
{
echo '<a href="galleri.php?image=',$files[$i],'"><img src="',$settings["picsdir"],$settings["thumbsdir"],$files[$i],'" alt="',$files[$i],'" /></a>';
}
?>
</div>
<div id="navigation">
<?
if ($key) echo '<a href="galleri.php?image=',$files[$key-1],'"><< Foregående</a> | ';
if ($key+1<count($files)) echo '<a href="galleri.php?image=',$files[$key+1],'">Næste >></a>';
?>
<br />Side:
<?
$totalpages=ceil($totalfiles/$settings["imagesperpage"]);
for ($i=0;$i<$totalpages;$i++)
{
$pagekey=$i*$settings["imagesperpage"];
echo '<a href="galleri.php?image=',$files[$pagekey],'">';
if ($settings["imagesperpage"]==1) echo $files[$pagekey];
else echo ' ',$i+1;
echo '</a>';
if ($i<$totalpages-1) echo ' | ';
}
?>
</div>
</div>
</body>
</html>
Men den opretter ikke billedet i "thumbs" nogle der kan se fejlen - kan nemlig ikke selv:S