Scripts
Foto galerie
Het werkt als volgt: Je zet de index.php in de root van een map, (bijvoorbeeld: /pics/) hierin zet je de map 'system', hierin komen de bestanden: main.css, folder.gif en jhead (zonder extensie). Als je een overzicht wilt hebben van grote foto's, maak je een map aan in de root (in dit geval dus: /pics/) je zet hier alle foto's is en je doet dan: chmod 777 mapnaam. De map die je dus hebt aangemaakt met de foto's erin moet dus ge-chmod worden naar 777. Dit omdat de thumbnails anders niet aangemaakt kunnen worden!! Als je hierna naar: www.domein.nl/pics gaat zul je de map naam te zien krijgen. Hier klik je op en de thumbnails worden getoond. Als je hierop klikt zul je de grote versie zien met een vorige/volgende systeem.
foto-galerie
<--------- index.php ------------->
<style type="text/css" media="screen">
<!--
@import url("system/main.css");
-->
</style>
<?
Function Numdirs($dir)
{
if(!$dir)
$dir = ".";
$handle = opendir($dir);
while($file = readdir($handle))
{
if(is_dir("$dir/$file") && $file != "thumbs" && $file != "." && $file != ".." && $file != "system")
$numdirs++;
}
return $numdirs;
}
Function NumPics($dir)
{
$handle = opendir($dir);
while($file = readdir($handle))
{
$filetype = substr($file,-3,3);
if ($filetype == "jpg" || $filetype == "JPG" )
$numpics++;
}
return $numpics;
}
function ThumbAvail($file)
{
$fp = popen("./jhead -st - '$file' 2>&1", "r");
while (!feof($fp)) {
$buf .= fread($fp, 1024);
}
if(strstr($buf,"thumbnail"))
return 0;
else
return 1;
}
Function ImgSize($file)
{
$fp = popen("./jhead '$file' 2>&1", "r");
while (!feof($fp)) {
$buf .= fread($fp, 1024);
}
//Resolution : 1536 x 2048
eregi("Resolution.* ([0-9]{1,}) x ([0-9]{1,})[^0-9]",$buf, $res);
$res[0] = trim(substr($res[0],12));
return $res;
}
Function GetNextName($name)
{
if(file_exists($name))
{
$handle = opendir('.');
while($file = readdir($handle))
{
$filetype = substr($file,-3,3);
if ($filetype == "jpg" || $filetype == "JPG" )
{
if($stop)
return($file);
if($file == $name)
$stop = 1;
}
}
}
}
Function GetPrevName($name)
{
if(file_exists($name))
{
$handle = opendir('.');
while($file = readdir($handle))
{
$filetype = substr($file,-3,3);
if ($filetype == "jpg" || $filetype == "JPG" )
{
if($file == $name)
return($oudefile);
else
$oudefile = $file;
}
}
}
}
Function CreateThumb($file)
{
if(!is_dir("thumbs"))
{
$res = @mkdir("thumbs",0777);
if(!$res)
{
echo "Geen rechten om thumbnails aan te maken.";
exit();
}
else
chmod("thumbs",0777);
}
//set_time_limit (30);
$imagehw = GetImageSize("$file");
$src_width = $imagehw[0];
$src_height = $imagehw[1];
// orrigineel
//$src_width > $src_height ? $dest_width = 100 : $dest_width = 75;
$src_width > $src_height ? $dest_width = 75 : $dest_width = 50;
$tmp = $src_width / $dest_width;
$dest_height = $src_height / $tmp;
$src_img = imagecreatefromjpeg("$file");
$dst_img = imagecreatetruecolor($dest_width,$dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $src_width, $src_height);
imagejpeg($dst_img, "thumbs/$file", 75);
imagedestroy($src_img);
imagedestroy($dst_img);
}
if($dir == "")
$dir = ".";
chdir($dir);
if($show == "")
{
if($dir == ".")
$showdir = "Overzicht categoriën";
elseif(substr($dir,0,2) == "./")
$showdir = substr($dir,2,strlen($dir));
else
$showdir = $dir;
echo "<table border=0 cellpadding=3 cellspacing=1 class=contenttable width=100%>\n\n";
if($showdir != "Overzicht categoriën")
{
$lastslash = strrpos($dir,"/");
$tmpdir = substr($dir,0,$lastslash);
$back = "<a href=\"$PHP_SELF?dir=$tmpdir\">Terug</a>";
}
echo "<tr><td class=kop1>$showdir</td><td align=right>$back</td></tr>";
echo "<tr><td colspan=2 height=20> </td></tr>\n";
echo "</table>";
$numdirs = NumDirs("");
if($numdirs)
{
//Eventuele dirs laten zien
echo "<table border=0 cellpadding=3 cellspacing=1 class=contenttable width=100%>\n\n";
echo "<tr class=row0><td colspan=3>Categorie</td></tr>\n";
$handle = opendir('.');
while($file = readdir($handle))
{
$bgclass == "row1" ? $bgclass = "row2" : $bgclass = "row1";
if(is_dir($file) && $file != "thumbs" && $file != "." && $file != ".." && $file != "system")
{
$numpics = Numpics($file);
$numdirs = Numdirs($file);
$shownumpics = "";
if($numpics)
$numpics == 1 ? $shownumpics = "1 foto" : $shownumpics = "$numpics foto's";
$shownumdirs = "";
if($numdirs)
$numdirs == 1 ? $shownumdirs = "1 subcategorie" : $shownumdirs = "$numdirs subcategorieen";
echo "<tr class=$bgclass><td align=center width=60><a href=\"$PHP_SELF?dir=$dir/$file\"><img src=system/folder.gif border=0></a></td><td><a href=\"$PHP_SELF?dir=$dir/$file\">$file</a></td><td width=100>$shownumpics$numdiv $shownumdirs</td></tr>\n";
}
}
echo "<tr><td height=20> </td></tr>\n";
echo "</table>";
}
$numpics = NumPics(".");
if($numpics)
{
//Losse Foto's laten zien
echo "<table border=1 bordercolor=#E4E2Ed style=\"border-color: #E4E2ED; border-width: 1px;\" cellpadding=5 cellspacing=0 width=100%>\n\n";
echo "<tr><td>";
echo "<table border=0 cellpadding=5 cellspacing=0 width=100%>\n\n";
//echo "<tr class=row0><td>Thumbnail</td><td>Filename</td><td>Filesize</td><td>Size</td></tr>\n";
$handle = opendir('.');
while($file = readdir($handle))
{
$filetype = substr($file,-3,3);
if ($filetype == "jpg" || $filetype == "JPG" )
{
$bgclass == "row1" ? $bgclass = "row2" : $bgclass = "row1";
$filesize = round(filesize($file)/1024);
$namelength= strlen($file)-4;
$file = substr($file,0,$namelength);
$imagehw = GetImageSize("$file.$filetype");
$width = $imagehw[0];
$height = $imagehw[1];
if(!file_exists("thumbs/$file.$filetype"))
CreateThumb("$file.$filetype");
if(!$width)
{
$imghw = ImgSize("$file.$filetype");
$width = $imghw[1];
$height = $imghw[2];
}
//-- edited by me..
if (!$count)
$count = 1;
if ($count == 1)
{
echo "<tr class=$bgclass>\n";
echo "<td align=center width=\"33%\"><a href=\"$PHP_SELF?dir=$dir&show=img&file=".rawurlencode("$file.$filetype")."\"><img src=\"$dir/thumbs/$file.$filetype\" border=0><a/></td>\n";
}
elseif ($count == 2)
echo "<td align=center width=\"33%\"><a href=\"$PHP_SELF?dir=$dir&show=img&file=".rawurlencode("$file.$filetype")."\"><img src=\"$dir/thumbs/$file.$filetype\" border=0><a/></td>\n";
elseif ($count == 3)
{
echo "<td align=center width=\"33%\"><a href=\"$PHP_SELF?dir=$dir&show=img&file=".rawurlencode("$file.$filetype")."\"><img src=\"$dir/thumbs/$file.$filetype\" border=0><a/></td>\n";
echo "</tr>\n";
$count = "0";
}
/*
echo "<tr class=$bgclass>\n";
echo "<td align=center width=100><a href=\"$PHP_SELF?dir=$dir&show=img&file=".rawurlencode("$file.$filetype")."\"><img src=\"$dir/thumbs/$file.$filetype\" border=0><a/></td>\n";
echo "<td><a href=\"$PHP_SELF?dir=$dir&show=img&file=".rawurlencode("$file.$filetype")."\">$file</a></td>\n";
echo "<td>$filesize kB</td>";
echo "<td>$width x $height</td>";
echo "</tr>";
*/
$count++;
$totalfilesize += $filesize;
$totalwidth += $width;
$totalheight += $height;
$numimg++;
}
}
}
if($numimg)
{
$avgwidth = round($totalwidth / $numimg);
$avgheight = round($totalheight / $numimg);
$avgfilesize = round($totalfilesize / $numimg);
$totalfilesize = round($totalfilesize / 1000,2);
echo "<tr><td height=20> </td></tr>\n";
echo "<tr class=row0><td colspan=4>Statistieken</td></tr>\n";
echo "<tr class=row1><td colspan=2>Totaal aantal foto's</td><td colspan=2>$numimg</td></tr>\n";
echo "<tr class=row2><td colspan=2>Gemiddelde foto</td><td colspan=2>$avgfilesize kB</td></tr>\n";
echo "<tr class=row1><td colspan=2>Gemiddelde afmetingen</td><td colspan=2>$avgwidth x $avgheight</td></tr>\n";
echo "<tr class=row2><td colspan=2>Totaal foto's</td><td colspan=2>$totalfilesize MB</td></tr>\n";
}
if ($dir != ".")
echo "</table></td></tr></table>";
}
elseif($show == "img")
{
$showfile = substr($file,0,-4);
echo "<table border=0 cellpadding=3 cellspacing=1 class=contenttable width=100%>\n\n";
$nextimg = GetNextName($file);
if($nextimg)
$next = "<a href=\"$PHP_SELF?dir=$dir&show=img&file=$nextimg\">Volgende</a>";
$previmg = GetPrevName($file);
if($previmg)
$prev = "<a href=\"$PHP_SELF?dir=$dir&show=img&file=$previmg\">Vorige</a>";
if($nextimg)
$img = "<a href=\"$PHP_SELF?dir=$dir&show=img&file=$nextimg\"><img border=0 src=\"$dir/$file\"></a>";
else
$img = "<img src=\"$dir/$file\">";
$prev && $next ? $div = " | " : $div = "";
echo "<tr><td class=kop1>$showfile</td><td align=right><a href=\"$PHP_SELF?dir=$dir\">Terug</a></td></tr>\n";
echo "<tr><td>$prev$div$next</td></tr>\n";
echo "<tr><td colspan=2>$img</td></tr>";
echo "<tr><td>$prev$div$next</td></tr>\n";
echo "</table>";
$lastslash = strrpos($HTTP_SERVER_VARS[SCRIPT_FILENAME],"/");
$root = substr($HTTP_SERVER_VARS[SCRIPT_FILENAME],0,$lastslash+1);
$fp = popen("$root/system/./jhead -se '$file' 2>&1", "r");
while (!feof($fp)) {
$buf .= fread($fp, 1024);
}
// echo $buf;
/*
if(!strstr($buf,"denied"))
{
$tmp = explode("\n",$buf);
for($i = 0; $i <= count($tmp); $i++)
{
if($tmp[$i] != "")
{
$tmp2 = explode(": ",$tmp[$i]);
$info[$i][key] = trim($tmp2[0]);
$info[$i][val] = trim($tmp2[1]);
}
}
echo "<table border=0 cellpadding=3 cellspacing=1 class=contenttable width=100%>\n\n";
echo "<tr><td height=20> </td></tr>\n";
echo "<tr class=row0><td colspan=2>Camera Instellingen</td></tr>\n";
for($i = 0; $i <= count($info); $i++)
{
if($info[$i][key] && $info[$i][val])
echo "<tr class=row1><td width=100>{$info[$i][key]}</td><td>{$info[$i][val]}</td></tr>\n";
elseif($info[$i][key] && !$info[$i][val])
echo "<tr class=row1><td colspan=2>{$info[$i][key]}</tr>\n";
}
}
echo "</table>";
*/
}
if ($dir == ".")
{
$path = "..";
$imgpath = "..";
//echo "</tr></table>";
}
else
{
$path = "../..";
$imgpath = "..";
}
?>
<------- DIT ALLES IN DE MAP -> system <- ----------------->
De map system kun je hier downloaden:
http://www.phphulp.nl/voorbeeld/pics/system.zip
Dit omdat hier ook een plaatje bij zit..
Reacties
0