php Fotoalbum
Verfasst: 24.11.2003 18:37
Hi,
habe kleines Problem
ich möchte mir ein Fotoalbum bauen, was automatisch Bilder aus
einen Ordner "Album" rausholt und auf einer Seite veröffentlicht.
hier mal den code:
für photobook.class.php
für index.php
Hoffe mir kann einer helfen...
Danke!
cu Stefan
habe kleines Problem
ich möchte mir ein Fotoalbum bauen, was automatisch Bilder aus
einen Ordner "Album" rausholt und auf einer Seite veröffentlicht.
hier mal den code:
für photobook.class.php
Code: Alles auswählen
<?php
class photobook {
var $rowlength;
var $thumbfolder;
var $picfolder;
var $types;
var $thumbs;
var $output;
/**
* @desrc Konstruktor temporär für PHP < 5 angelegt.
* @return void
*/
function photobook($length, $thumbs, $pics, $types) {
$this->__construct($length, $thumbs, $pics, $types);
}
/**
* @descr Konstruktor nach PHP 5.
* @return void
*/
function __construct ($length, $thumbs, $pics, $types) {
$this->rowlength = $length;
$this->thumbfolder = $thumbs;
$this->picfolder = $pics;
$this->types = $types;
}
/**
* @desrc führt alle notwendigen Handlungen durch und leifert fertigen Output
* @return string output data
*/
function showbook() {
$this->thumbs = $this->readthumbs();
$this->output = $this->generate();
return $this->output;
}
/**
* @descr Funktion zum Einlesen der Thumbs
* @return array thumbnail names
*/
function readthumbs() {
$dir = opendir($this->thumbfolder);
while(($file = readdir($dir)) != false) {
if (preg_match("/^index/", $file)) continue;
if (preg_match("/\.\.?$/", $file)) continue;
foreach($this->types as $typ) {
if(preg_match("/\.".$typ."$/i", $file)) $thumbs[] = $file;
};
};
return $thumbs;
}
/**
* @descr Erstellt die Ausgabe
* @return string output data
*/
function generate() {
$output = ' ';
$sizes = ' ';
$widths = ' ';
$heights = ' ';
$rows = floor(sizeof($this->thumbs) / $this->rowlength);
$rest = sizeof($this->thumbs) - $rows * $this->rowlength;
foreach($this->thumbs as $key => $value) {
$sizes[] = getimagesize($this->thumbfolder.'/'.$value);
$widths[] = $sizes[$key][0];
$heights[] = $sizes[$key][1];
}
$maxwidth = max($widths);
$maxheight = max($heights);
for($i=0;$i<$rows;$i++) {
$output .= '<table cellpadding="0" cellspacing="0" border="0" style="margin-bottom:7px; table-layout:fixed"><tr>'."\n";
for($j=0;$j<$this->rowlength;$j++) {
$thumbnow = $i * $this->rowlength + $j;
$picnow = ereg_replace("k_", "", $this->thumbs[$thumbnow]);
$output .= '<td align="center" height="'.($maxheight + 8).'" width="'.($maxwidth + 8).'" style="background-color:#E1F0FF; border:1px white solid"><a href="'.$this->picfolder.'/'.$picnow.'" target="_blank"><img src="'.$this->thumbfolder.'/'.$this->thumbs[$thumbnow].'" width="'.$widths[$thumbnow].'" height="'.$heights[$thumbnow].'" border="0" alt="zum Vergrößern klicken" style="border:1px white solid"></a></td>'."\n";
if ($j < $this->rowlength - 1) $output .= '<td width="7"> </td>'."\n";
}
$output .= '</tr></table>'."\n";
}
if($rest <> 0) {
$output .= '<table cellpadding="0" cellspacing="0" border="0" style="table-layout:fixed"><tr>'."\n";
for($k=0;$k<$rest;$k++) {
$thumbnow = $rows * $this->rowlength + $k;
$picnow = ereg_replace("k_", "", $this->thumbs[$thumbnow]);
$output .= '<td align="center" height="'.($maxheight + 8).'" width="'.($maxwidth + 8).'" style="background-color:#E1F0FF; border:1px white solid"><a href="'.$this->picfolder.'/'.$picnow.'" target="_blank"><img src="'.$this->thumbfolder.'/'.$this->thumbs[$thumbnow].'" width="'.$widths[$thumbnow].'" height="'.$heights[$thumbnow].'" border="0" alt="zum Vergrößern klicken" style="border:1px white solid"></a></td>'."\n";
if ($k < $rest - 1) $output .= '<td width="7"> </td>'."\n";
}
$output .= '</tr></table>'."\n";
};
return $output;
}
}
?>
Code: Alles auswählen
<?php
include("./album/photobook.class.php")
$photobook = new photobook(##2##, './album/', './album/', array('jpg', 'gif', 'png', 'jpeg'));
echo $photobook->showbook();
?>
Danke!
cu Stefan