Snowball: Jeg er ikke helt enig. Der er blevet bedt om yderligere rettelser, så som visning af billeder i rækker, samt flere filformater.
Den fulde kode kan ses her:
<?php
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Strict //EN\" \"
http://www.w3.org/TR/html4/strict.dtd\">\n";echo "<html>\n";
echo "<head>\n";
echo "<title>Inden den blev malet</title>\n";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\">\n";
echo "</head>\n";
echo "<body>\n";
echo "<div id=\"content\">\n";
echo "<h2>Klik på et billede for STORT billede </h2>\n";
echo '<img border="0" src="malet/2.jpg" width="25" height="45"><a href="/malet/index.php"><b> Malet</a>'."\n";
function resize( $filename, $newfilename, $maxw, $maxh, $quality=85 ){
$ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
switch($ext){
case 'jpeg':
case 'jpe':
case 'jpg':
$srcim = imagecreatefromjpeg( $filename );
break;
case 'gif':
$srcim = imagecreatefromgif( $filename );
break;
case 'png':
$srcim = imagecreatefrompng( $filename );
break;
case 'bmp':
$srcim = imagecreatefrompng( $filename );
break;
default:
return false;
}
$ow = imagesx( $srcim );
$oh = imagesy( $srcim );
$wscale = $maxw / $ow;
$hscale = $maxh / $oh;
$scale = min( $hscale, $wscale );
$nw = round( $ow * $scale, 0 );
$nh = round( $oh * $scale, 0 );
$dstim = imagecreatetruecolor( $nw, $nh );
imagecopyresampled( $dstim, $srcim, 0, 0, 0, 0, $nw, $nh, $ow, $oh );
switch($ext){
case 'jpeg':
case 'jpe':
case 'jpg':
imagejpeg( $dstim, $newfilename, $quality );
break;
case 'gif':
imagegif( $dstim, $newfilename );
break;
case 'png':
$png_q = floor( abs( $quality / 10 - 9.9 ) );
imagepng( $dstim, $newfilename, $png_q );
break;
case 'bmp':
imagegif( $dstim, $newfilename );
break;
default:
return false;
}
imagedestroy( $dstim );
imagedestroy( $srcim );
return file_exists($newfilename);
}
$dir = getcwd();
$allowExt = array("jpg","JPG","bmp","BMP","png","PNG");
// Open a known directory, and proceed to read its contents
if(is_dir($dir)){
if ($dh = opendir($dir)){
$fileArray = array();
while(($file = readdir($dh)) !== false){
$arr = explode (".", $file);
$extension = end($arr);
if(in_array($extension,$allowExt)){
if(file_exists("thumb_" . $file) || preg_match('/^thumb_/', $file)){
;
}else{
resize($file, getcwd() . "/thumb_" . $file, 150, 150);
}
if(!preg_match('/^thumb_/', $file)){
$thumb = "thumb_" . $file;
$fileArray[$thumb] = $file;
}
}
}
closedir($dh);
}
}
$counter = 0;
if(count($fileArray)>0){
echo '<table id="centerTable"><tr>'."\n";
foreach($fileArray as $thumb => $file){
echo "<td><table><tr><td><a target=\"_blank\" href=\"" . $file . "\"><img src=\"".$thumb."\"></a></td></tr>\n";
echo "<tr><td>" . $file . "</td></tr></table></td>\n";
if(($counter % 4) == 4){
echo '</tr><tr>'."\n";
}
$counter++;
}
echo '</tr></table>'."\n";
}else{
echo "Vi har ikke uploadet nogle billeder endnu, de kommer...";
}
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
?>