Gå til innhold

Thumbs med Mortz bildegalleri


Anbefalte innlegg

Hei, noen som kjenner til Mortz sitt script for bildegalleri, som

du finner her http://mortz.tjokk.net/phpscripts ?

Har problemer med at scriptet ikke lager thumbs av bildene mine.

Det lager riktig mappenavn under thumbs folderen, men ikke bilder altså.

Ellers funker galleriet. Har GD på server, og chmodda thumbs folderen til 0777.

Noen som har hatt lignende problemer, eller har tips?

Lenke til kommentar
Videoannonse
Annonse

Forsøker også å legge ut koden her, hvis noen kan se hvor problemet ligger.

Kjempefint om noen hadde hatt tips. ;)

Skjult tekst: (Marker innholdet i feltet for å se teksten):

<div class="gallery">
<?php


$URLToThisPage  = "index.php?page=bildegalleri";	// URL til sida som viser galleriet.
       	// F.eks "index.php"
       	// Eller "index.php?page=bildegalleri" hvis du bruker includescript.

$PhotoDir  	= "photos";	// mappa dine album ligger under
$ThumbDir  	= "thumbs";	// mappa der thumbs skal legges. må chmoddes 0777!

$LogFile  	= "data/gallery_log.txt";  // må chmoddes 0666!
$CommentFile  = "data/gallery_comments.txt";	// må chmoddes 0666!

$SmileyDir  	= "img/smileys"; // mappa for smileys

$ThumbGenerator  = "GD";	// Hvilken extension PHP skal bruke for å lage thumbs.
     	// Sett til "IM" om du vil bruke ImageMagick!
     	// Sett til "GD" om du vil bruke GD, som er standard!

$ImagesPerRow  = 5;
$NumberOfRows  = 10;
$GalsPerRow  	= 2;
$GalRows  	= 10;
$MaxWidth  	= 640;
$MaxHeight  	= 480;

$CommentInputSize	= 97;
$MaxLenComment  = 300;
$MaxWordLen  	= 50;


/*** SCRIPTET STARTER HER ***************************************************/
/*** (ikke gjør endringer med mindre du vet hva du gjør! =) *****************/


$action = $_GET['action'];
$gallery = $_GET['gallery'];
$photo = $_GET['photo'];
$start = $_GET['start'];
$astart = $_GET['astart'];
$comment = $_POST['comment'];

$phpSelf = explode("?", $URLToThisPage);
if (!strstr($_SERVER['PHP_SELF'], $phpSelf[0])) die("Permission denied.");
if (ereg("^[^?]+$", $URLToThisPage)) $URLToThisPage = $URLToThisPage . "?";

if (!file_exists($LogFile)) {
$fp = @fopen($LogFile, "w");
@fwrite($fp, "");
@fclose($fp);
@chmod($LogFile, 0777);
}
if (!file_exists($CommentFile)) {
$fp = @fopen($CommentFile, "w");
@fwrite($fp, "");
@fclose($fp);
@chmod($CommentFile, 0777);
}

// lage thumbs
function createThumb($filename, $directory, $destination, $width, $height) {
if (!is_dir($destination)) { mkdir($destination, 0777); chmod($destination, 0777); }

if ($GLOBALS['ThumbGenerator'] == "IM") {
 system("convert -resize ".$width."x".$height." $directory/$filename $destination/$filename");
}
else {
 $size = getimagesize("$directory/$filename");
 if (eregi(".+\.gif$", $filename) && !file_exists("$destination/$filename")) {
 	$source = imagecreatefromgif("$directory/$filename");
 	$thumb = @imagecreatetruecolor($width, $height)
 	or
 	$thumb = imagecreate($width, $height);
 	imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
 	imagegif($thumb, "$destination/$filename");
 	imagedestroy($thumb);
 	imagedestroy($source);
 	chmod("$destination/$filename", 0777);
 }
 if (eregi(".+\.jpe?g$", $filename) && !file_exists("$destination/$filename")) {
 	$source = imagecreatefromjpeg("$directory/$filename");
 	$thumb = @imagecreatetruecolor($width, $height)
 	or
 	$thumb = imagecreate($width, $height);
 	imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
 	imagejpeg($thumb, "$destination/$filename", 75);
 	imagedestroy($thumb);
 	imagedestroy($source);
 	chmod("$destination/$filename", 0777);
 }
 if (eregi(".+\.png$", $filename) && !file_exists("$destination/$filename")) {
 	$source = imagecreatefrompng("$directory/$filename");
 	$thumb = @imagecreatetruecolor($width, $height)
 	or
 	$thumb = imagecreate($width, $height);
 	imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
 	imagepng($thumb, "$destination/$filename");
 	imagedestroy($thumb);
 	imagedestroy($source);
 	chmod("$destination/$filename", 0777);
 }
}
}

// finne filstørrelse
function getFilesize($filename) {
$filesize = filesize($filename);
if ($filesize >= 1073741824) $filesize = round($filesize / 1073741824 * 100) / 100 . " GB";
elseif ($filesize >= 1048576) $filesize = round($filesize / 1048576 * 100) / 100 . " MB";
elseif ($filesize >= 1024) $filesize = round($filesize / 1024 * 100) / 100 . " KB";
else { $filesize = $filesize . " B"; }
return $filesize;
}

// finne ut hvor mange ganger bildet har blitt vist + oppdatere
function updateDownloads($filename, $LogFile) {
$done = 0;
$line = 0;
$file = file($LogFile);
while ($file[$line]) {
 $a = explode("|", $file[$line]);
 if ($a[0] == $filename) {
 	$a[1]++;
 	$file[$line] = implode($a, "|");
 	$done = 1;
 	$dls = $a[1];
 }
 $line++;
}
$a = implode($file, "");
$fp = fopen($LogFile, "w");
if ($done == 1) fwrite($fp, $a);
else fwrite($fp, $a . $filename . "|1|\n");
fclose($fp);
if (!isset($dls)) $dls = 1;
return $dls;
}

// finne nye mål, men beholde proposjoner
function fit2box($filename, $MaxWidth, $MaxHeight) {
$size = getimagesize($filename);
$width = $size[0];
$height = $size[1];
if (($width > $MaxWidth) || ($height > $MaxHeight)) {
 $width = round($size[0] * 100 / round($size[0]+$size[1]));
 $height = round($size[1] * 100 / round($size[0]+$size[1]));
 if (($size[0] >= $MaxWidth) && ($size[1] >= $MaxHeight)) {
 	$height = round($MaxWidth * 100 / $width * $height / 100);
 	$width = $MaxWidth;
 	if ($height >= $MaxHeight) {
   $width = round($MaxHeight * 100 / $height * $width / 100);
   $height = $MaxHeight;
 	}
 }
 elseif ($size[0] >= $MaxWidth) {
 	$height = round($MaxWidth * 100 / $width * $height / 100);
 	$width = $MaxWidth;
 }
 elseif ($size[1] >= $MaxHeight) {
 	$width = round($MaxHeight * 100 / $height * $width / 100);
 	$height = $MaxHeight;
 }
}
return array($width, $height);
}

if (($action == "view") && isset($gallery) && is_dir("$PhotoDir/$gallery")) {

// vise bilde
if (isset($photo) && file_exists("$PhotoDir/$gallery/$photo") && !is_dir("$PhotoDir/$gallery/$photo")) {
 if (eregi(".+\.gif$", $photo) || eregi(".+\.jpe?g$", $photo) || eregi(".+\.png$", $photo)) {

 	$true_dimensions = getimagesize("$PhotoDir/$gallery/$photo");
 	$dimensions = fit2box("$PhotoDir/$gallery/$photo", $MaxWidth, $MaxHeight);
 	$filesize = getFilesize("$PhotoDir/$gallery/$photo");
 	$views = updateDownloads("$gallery/$photo", $LogFile);
 	$current_photo = $photo;

 	// putte alle bildene inn i et array
 	if ($handle = opendir("$PhotoDir/$gallery")) {
   $photos = array();
   while (false !== ($photo = readdir($handle))) {
         	if ($photo != "." && $photo != ".." && !is_dir("$PhotoDir/$gallery/$photo")) {
     if (eregi(".+\.gif$", $photo) || eregi(".+\.jpe?g$", $photo) || eregi(".+\.png$", $photo)) {
     	array_push($photos, $photo);
     }
   	}
   }
   closedir($handle);
 	}

 	natcasesort($photos); // sortere etter navn
 	$current = array_search($current_photo, $photos)+1;
 	$total = count($photos);

 	// $start hax
 	$start = round((100*($current-1)/($ImagesPerRow*$NumberOfRows)-50)/100);
 	$start = $start*$ImagesPerRow*$NumberOfRows+1;

 	echo "<h1>Viser bilde $current av $total i '$gallery'</h1>\n";
 	echo "<table cellpadding=\"0\" cellspacing=\"4\"><tr>\n";
 	echo "<td class=\"photo\">\n";
 	echo "<a href=\"$PhotoDir/$gallery/$current_photo\" target=\"_blank\"><img src=\"$PhotoDir/$gallery/$current_photo\" width=\"$dimensions[0]\" height=\"$dimensions[1]\" alt=\"$current_photo\"></a>\n";

 	// kommentering
 	if ($LoggedIn == true) {
   echo "<form action=\"$URLToThisPage&action=view&gallery=$gallery&photo=$current_photo&astart=$astart&start=$start\" method=\"post\">\n";
   echo "<input type=\"text\" name=\"comment\" size=\"$CommentInputSize\" value=\"";
   if (isset($comment)) {
   	$comment = stripslashes($comment);
   	$comment = ltrim($comment);
   	$comment = rtrim($comment);
   	if (strlen($comment) > $MaxLenComment) echo "ERROR! Kommentaren er for lang! Max $MaxLenComment tegn!";
   	else {
     $comment = htmlspecialchars($comment);
     $comment = wordwrap($comment, $MaxWordLen, " ", 1);
     $comment = str_replace("æ","æ",$comment);
     $comment = str_replace("ø","ø",$comment);
     $comment = str_replace("å","å",$comment);
     $comment = str_replace("Æ","Æ",$comment);
     $comment = str_replace("Ø","Ø",$comment);
     $comment = str_replace("Å","Å",$comment);
     $comment = str_replace("|","|",$comment);
     echo "$comment";
     $done = 0;
     $line = 0;
     $file = file($CommentFile);
     while ($file[$line]) {
     	$a = explode("|", $file[$line]);
     	if ($a[0] == "$gallery/$current_photo") {
       $a[1] = $comment;
       $file[$line] = implode($a, "|");
       $done = 1;
     	}
     	$line++;
     }
     $a = implode($file, "");
     $fp = fopen($CommentFile, "w");
     if($done == 1) fwrite($fp, $a);
     else fwrite($fp, $a . "$gallery/$current_photo" . "|$comment|\n");
     fclose($fp);
   	}
   }
   else {
   	$line = 0;
   	$file = file($CommentFile);
   	while ($file[$line]) {
     $a = explode("|", $file[$line]);
     if ($a[0] == "$gallery/$current_photo") echo $a[1];
     $line++;
   	}
   }
   echo "\"> <input type=\"submit\" value=\"OK\">\n";
   echo "</form>\n";
 	}
 	else {
   $line = 0;
   $file = file($CommentFile);
   while ($file[$line]) {
   	$a = explode("|", $file[$line]);
   	if ($a[0] == "$gallery/$current_photo") {
     $comment = $a[1];
     $comment = str_replace("X(","<img src=\"$SmileyDir/angry.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":f","<img src=\"$SmileyDir/flirt.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":x","<img src=\"$SmileyDir/dead.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":(","<img src=\"$SmileyDir/frown.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":h","<img src=\"$SmileyDir/cool.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":i","<img src=\"$SmileyDir/idea.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":)","<img src=\"$SmileyDir/smile.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(";)","<img src=\"$SmileyDir/wink.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":l","<img src=\"$SmileyDir/hrmpf.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":o","<img src=\"$SmileyDir/redface.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":00","<img src=\"$SmileyDir/look.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":p","<img src=\"$SmileyDir/tounge.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":P","<img src=\"$SmileyDir/tounge.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":q","<img src=\"$SmileyDir/quest.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":r","<img src=\"$SmileyDir/shame.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":D","<img src=\"$SmileyDir/biggrin.gif\" alt=\"\" class=\"nb\">",$comment);
     $comment = str_replace(":e","<img src=\"$SmileyDir/supergrin.gif\" alt=\"\" style=\"nb\">",$comment);
     echo "<i>$comment</i>\n";
   	}
   	$line++;
   }
 	}

 	echo "</td>\n";
 	echo "</tr><tr>\n";
 	echo "<td><div class=\"nav\">";
 	if ($current != 1) {
   $prev = $current-2;
   $prev = $photos[$prev];
   echo "<a href=\"$URLToThisPage&action=view&gallery=$gallery&photo=$prev&astart=$astart&start=$start\">« Forrige bilde</a>";
 	}
 	if (($current != 1) && ($current != $total)) echo " :: ";
 	if ($current != $total) {
   $next = $current;
   $next = $photos[$next];
   echo "<a href=\"$URLToThisPage&action=view&gallery=$gallery&photo=$next&astart=$astart&start=$start\">Neste bilde »</a>";
 	}
 	echo "</div></td>\n";
 	echo "</tr></table>\n";
 	echo "<p>Filnavn: <b>$current_photo</b><br>\n";
 	echo "Album: <b>$gallery</b><br>\n";
 	echo "Størrelse: <b>$filesize</b><br>\n";
 	echo "Dimensjoner: <b>$true_dimensions[0] x $true_dimensions[1]</b><br>\n";
 	echo "Visninger: <b>$views</b></p>\n";
 	echo "<p><a href=\"$URLToThisPage&action=view&gallery=$gallery&astart=$astart&start=$start\">Gå tilbake</a></p>\n";
 }
}

// vise galleri
else {

 $ImagesPerPage = $ImagesPerRow*$NumberOfRows;
 echo "<h1>Viser bilder i '$gallery'</h1>\n";
 echo "<table cellpadding=\"0\" cellspacing=\"4\"><tr>\n";
 $b = 0;

 // putte alle bildene inn i et array
 if ($handle = opendir("$PhotoDir/$gallery")) {
 	$photos = array();
 	while (false !== ($photo = readdir($handle))) {
         if ($photo != "." && $photo != ".." && !is_dir("$PhotoDir/$gallery/$photo")) {
   	if (eregi(".+\.gif$", $photo) || eregi(".+\.jpe?g$", $photo) || eregi(".+\.png$", $photo)) {
     array_push($photos, $photo);
   	}
   }
 	}
 	closedir($handle);
 }

 natcasesort($photos); // sortere etter navn

 $a = 0;
 while ($photos[$a]) {
 	$photo = $photos[$a];
 	$a++;
 	if ((isset($start) == 0) || ($start <= 0)) $start = 1;
 	if (($a >= $start) && ($a <= $start+$ImagesPerPage-1)) {
   $filename = $photo;
   $length = strlen($filename);
   if ($length >= 18) {
   	$filename = substr($filename, 0, 15) . "...";
   }
   $b++;
   echo "<td class=\"thumb\"><a href=\"$URLToThisPage&action=view&gallery=$gallery&photo=$photo&astart=$astart&start=$start\" class=\"thumb\">";
   echo "<img src=\"$ThumbDir/$gallery/$photo\" alt=\"$photo\"><br>$filename</a></td>\n";
   if ($b == $ImagesPerRow) {
   	$b = 0;
   	echo "</tr><tr>\n";
   }
 	}
 }
 while ($b < $ImagesPerRow) {
 	echo "<td></td>\n";
 	$b++;
 }

 echo "</tr><tr>\n";
 echo "<td colspan=\"$ImagesPerRow\"><div class=\"nav\">";
 $c = round(round(100 * $start / $ImagesPerPage -50) / 100 +1); // den aktive siden
 if ($start == 1) $c = 1;
 if ($start >= $ImagesPerPage * $ImagesPerPage +1) $c = $c-1;
 $d = round(round(100 * $a / $ImagesPerPage +49) / 100); // hvor mange sider
 $e = $start + $ImagesPerPage-1; // siste bilde på siden
 if ($e >= $a) $e = $a;
 $f = ($d-1) * $ImagesPerPage +1; // start=$f for å komme til siste side
 $next = $start+$ImagesPerPage;
 $prev = $start-$ImagesPerPage;
 if ($prev <= 1) $prev = 1;
 if ($start > $ImagesPerPage) echo "<a href=\"$URLToThisPage&action=view&gallery=$gallery&astart=$astart&start=$prev\">« Forrige side</a>";
 if (($start > $ImagesPerPage) && ($a >= $start+$ImagesPerPage)) echo " :: ";
 if ($a >= $start+$ImagesPerPage) echo "<a href=\"$URLToThisPage&action=view&gallery=$gallery&astart=$astart&start=$next\">Neste side »</a>";
 echo "</div></td>\n";
 echo "</tr></table>\n";
 echo "<p>Du er nå på side <b>$c</b> av <b>$d</b><br>\n";
 echo "Viser nå bilder fra <b>$start</b> til <b>$e</b><br>\n";
 echo "Totalt: <b>$a</b> bilder</p>\n";
 echo "<p><a href=\"$URLToThisPage&action=view&astart=$astart\">Gå tilbake</a></p>\n";
}
}

// vise gallerier
else {

$GalsPerPage = $GalsPerRow*$GalRows;
echo "<h1>Bildegalleri</h1>\n";
echo "<table cellpadding=\"0\" cellspacing=\"4\"><tr>\n";
$b = 0;
$b2 = 0;

// putte alle mappene inni et array
if ($handle = opendir($PhotoDir)) {
 $galleries = array();
    while (false !== ($gallery = readdir($handle))) {
 	if ($gallery != "." && $gallery != ".." && is_dir("$PhotoDir/$gallery")) {
   array_push($galleries, $gallery);
 	}
 }
    closedir($handle);
}

natcasesort($galleries); // sortere etter navn

$a2 = 0;
$a = 0;
while ($galleries[$a]) {
 $gallery = $galleries[$a];
 $a++;

 // putte alle bildene inn i et array
 if ($handle = opendir("$PhotoDir/$gallery")) {
 	$photos = array();
 	while (false !== ($photo = readdir($handle))) {
         if ($photo != "." && $photo != ".." && !is_dir("$PhotoDir/$gallery/$photo")) {
   	if (eregi(".+\.gif$", $photo) || eregi(".+\.jpe?g$", $photo) || eregi(".+\.png$", $photo)) {
     array_push($photos, $photo);

     // mekke thumbs
     $dimensions = fit2box("$PhotoDir/$gallery/$photo", 100, 100);
     createThumb($photo, "$PhotoDir/$gallery", "$ThumbDir/$gallery", $dimensions[0], $dimensions[1]);
   	}
   }
 	}
 	closedir($handle);
 }

 $total = count($photos);
 if ($total != 0) {
 	$a2++; // antall album
 	$b = $b + $total; // antall bilder
 	if ((isset($astart) == 0) || ($astart <= 0)) $astart = 1;
 	if (($a >= $astart) && ($a <= $astart+$GalsPerPage-1)) {
   srand((float) microtime() * 10000000);
   if (count(photos)>1) $random = array_rand($photos, $total);
   else $random[0] = 0;
   $random = $photos[$random[0]];
   echo "<td class=\"thumb\"><a href=\"$URLToThisPage&action=view&gallery=$gallery&astart=$astart\"><img src=\"$ThumbDir/$gallery/$random\" alt=\"$gallery\"></a></td>\n";
   echo "<td><div class=\"title\"><a href=\"$URLToThisPage&action=view&gallery=$gallery&astart=$astart\">$gallery</a>   </div>";
   echo "Antall bilder: <b>$total</b>   </td>\n";
   $b2++;
   if ($b2 == $GalsPerRow) {
   	$b2 = 0;
   	echo "</tr><tr>\n";
   }
 	}
 }
}
while ($b2 < $GalsPerRow) {
 echo "<td></td><td></td>\n";
 $b2++;
}

echo "<td colspan=\"". 2*$GalsPerRow ."\"><div class=\"nav\">";
$c = round(round(100 * $astart / $GalsPerPage -50) / 100 +1); // den aktive siden
if ($astart == 1) $c = 1;
if ($astart >= $GalsPerPage * $GalsPerPage +1) $c = $c-1;
$d = round(round(100 * $a / $GalsPerPage +49) / 100); // hvor mange sider
if ($d < 1) $d = 1;
$next = $astart+$GalsPerPage;
$prev = $astart-$GalsPerPage;
if ($prev <= 1) $prev = 1;
if ($astart > $GalsPerPage) echo "<a href=\"$URLToThisPage&action=view&astart=$prev\">« Forrige side</a>";
if (($astart > $GalsPerPage) && ($a >= $astart+$GalsPerPage)) echo " :: ";
if ($a >= $astart+$GalsPerPage) echo "<a href=\"$URLToThisPage&action=view&astart=$next\">Neste side »</a>";
echo "</div></td>\n";
echo "</tr></table>\n";
if ($b!=0&&$a2!=0) $g = round($b / $a2); // gjennomsnitt
echo "<p>Du er nå på side <b>$c</b> av <b>$d</b>\n";
echo "<br><br>Totalt: <b>$a2</b> album og <b>$b</b> bilder.<br>\n";
echo "I gjennomsnitt <b>$g</b> bilder i hvert album.</p>\n";
}

?>
</div>

Lenke til kommentar

Nå tror jeg at jeg gir opp dette galleriet, etter utallig feilsøking og prøving, får jeg jo ikke generert thumbs. Synd ettersom galleriet ser bra ut ellers.

 

Noen som kan anbefalle et annet script som

- Må generere thumbs automatisk

- Støtte flere album og opplasting via ftp.

- Se helt "rent" ut, slik at jeg selv kan definere layout osv. med css

 

Har søkt endel rundt uten å finne noe jeg kan bruke...

Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...