http://www.stardestroyer.net/Mike/Family/
Nothing complicated; it just parses some directory trees, looking for JPEG files and then assembles webpages out of them. If it finds a file with the same name and a .txt suffix, it uses that file as the caption. If it finds a file with the same name and a _THM.JPG suffix, it treats it as a thumbnail and displays it while linking to the real image. I don't have much experience optimizing PHP for performance though, and I don't know how optimal this solution is. Any PHP experts in the house? The code looks like this:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
<?
if ($imagedir) $maindir = preg_replace("/^\/|\.+/",".",addslashes("$imagedir"));
else $maindir = "Main";
if (!file_exists($maindir) && !file_exists("../PhotoAlbum/$maindir")) $maindir = "Main";
echo " <TITLE>The Wong Clan Photo Album - $maindir</TITLE>\n";
?>
<META NAME="AUTHOR" CONTENT="Michael Wong">
<LINK REL="STYLESHEET" TYPE="text/css" HREF="../style.css">
</HEAD>
<BODY>
<TABLE WIDTH="100%" BORDER=0 CELLPADDING=4 CELLSPACING=0>
<TR>
<TD WIDTH=125>
<A HREF="../index.html"><IMG SRC="../turhome.gif" ALIGN=LEFT WIDTH=30 HEIGHT=30 BORDER=0 ALT="Home"><B>Home</B></A>
</TD>
<TD COLSPAN=4>
<?
echo " <H1 ALIGN=CENTER STYLE=\"margin-bottom:0in\">The Wong Clan Photo Album - $maindir</H1>\n";
echo " <P ALIGN=CENTER STYLE=\"margin-top:0in\">";
if (!file_exists($maindir))
echo "Click on images to enlarge";
else
echo " ";
echo "</P>\n";
?>
</TD>
</TR>
<TR VALIGN=TOP>
<TD WIDTH=125>
<HR>
<?
echo " <P><B><A HREF=\"$PHP_SELF?imagedir=Main\">Main</A></B></P>\n";
echo " <P><B><A HREF=\"$PHP_SELF?imagedir=Matthew\">Matthew</A></B></P>\n";
echo " <P><B><A HREF=\"$PHP_SELF?imagedir=David\">David</A></B></P>\n";
echo " <P><B><A HREF=\"$PHP_SELF?imagedir=Fuzzy\">Fuzzy</A></B></P>\n";
?>
<HR>
<?
$readdir = "../PhotoAlbum";
$mydir = opendir($readdir);
while($fn = readdir($mydir))
{
if (filetype("$readdir/$fn") == "dir" && $fn != "." && $fn != "..")
$dir_array[] = $fn;
}
closedir($mydir);
if (count($dir_array) > 0) sort($dir_array);
for ($i=0; $i < count($dir_array); $i++)
echo " <P><B><A HREF=\"$PHP_SELF?imagedir=$dir_array[$i]\">$dir_array[$i]</A></B></P>\n";
?>
<HR>
</TD>
<TD WIDTH=20 STYLE="background:black"> </TD>
<TD VALIGN=TOP STYLE="background:black">
<?
if (file_exists($maindir))
{
$mydir = opendir($maindir);
$side = "left";
while($fn = readdir($mydir))
{
if ( strstr($fn,'jpg') )
$file_array[] = $fn;
}
closedir($mydir);
if (count($file_array) > 0) sort($file_array);
for ($i=0; $i < count($file_array); $i++)
{
echo " <TABLE STYLE=\"background:black\">\n";
echo " <TR><TD COLSPAN=2 STYLE=\"background:black\"> </TD></TR>\n";
echo " <TR VALIGN=MIDDLE><TD STYLE=\"background:black;color:white\">";
if ( $side == "right" )
{
echo "<IMG SRC=\"$maindir/$file_array[$i]\" BORDER=1 ALT=\"Image\"></TD>\n";
echo "<TD STYLE=\"background:black;color:white\">";
}
$textfile=str_replace('.jpg','.txt',$file_array[$i]);
if (file_exists("$maindir/$textfile"))
{
$textopen=fopen("$maindir/$textfile", "r");
$textdata=preg_replace("/\n\n/","<BR><BR>",htmlspecialchars(fread($textopen, filesize("$maindir/$file_array[$i]"))));
fclose($textopen);
echo $textdata;
}
echo "</TD>";
if ( $side == "left" )
{
echo " <TD STYLE=\"background:black;color:white\">";
echo "<IMG SRC=\"$maindir/$file_array[$i]\" BORDER=1 ALT=\"Image\"></TD>";
}
echo "</TR>\n";
echo " <TR><TD COLSPAN=2 STYLE=\"background:black\"> </TD></TR>\n";
echo " </TABLE>\n";
if ( $side == "right" )
$side = "left";
else if ( $side == "left" )
$side = "right";
}
}
else
{
$altdir = "../PhotoAlbum/$maindir";
$mydir = opendir($altdir);
$dir_array2[] = ".";
while($fn = readdir($mydir))
{
if (filetype("$altdir/$fn") == "dir" && $fn != "." && $fn != "..")
$dir_array2[] = $fn;
}
closedir($mydir);
sort($dir_array2);
echo " <TABLE STYLE=\"background:black\">\n";
for ($x=0; $x < count ($dir_array2); $x++)
{
$photodir = "$altdir/$dir_array2[$x]";
$mydir = opendir($photodir);
//for ($i=0; $i < count($file_array); $i++)
// {
// unset ($file_array[$i]);
// array_pop($file_array);
// }
unset($file_array);
while($fn = readdir($mydir))
{
if ( stristr($fn,'jpg') && !strstr($fn,'_THM.JPG'))
$file_array[] = $fn;
}
closedir($mydir);
if (count($file_array) > 0)
{
sort($file_array);
for ($i=0; $i < count($file_array); $i++)
{
$thumbfile=str_replace('.jpg','_THM.JPG',str_replace('.JPG','_THM.JPG',$file_array[$i]));
$textfile=str_replace('.jpg','.txt',str_replace('.JPG','.txt',$file_array[$i]));
echo " <TR>";
echo "<TD COLSPAN=2 STYLE=\"background:black\"> </TD></TR>\n";
echo " <TR VALIGN=MIDDLE>\n";
echo " <TD WIDTH=132 STYLE=\"background:black;color:white\" ALIGN=CENTER>";
echo "<A HREF=\"$photodir/$file_array[$i]\" TARGET=\"_blank\">";
echo "<IMG SRC=\"$photodir/$thumbfile\" BORDER=0 ALT=\"Image\"></A></TD>\n";
echo " <TD STYLE=\"background:black;color:white\">";
if (file_exists("$photodir/$textfile"))
{
$textopen=fopen("$photodir/$textfile", "r");
$textdata=preg_replace("/\n\n/","<BR><BR>",htmlspecialchars(fread($textopen, filesize("$photodir/$file_array[$i]"))));
fclose($textopen);
echo $textdata;
}
else
{
echo "<SPAN STYLE=\"font-size:10px;color:gray\">";
echo "$dir_array2[$x]/$file_array[$i]</SPAN>";
}
echo "</TD>\n";
echo " </TR>\n";
}
}
}
echo " <TR><TD COLSPAN=2 STYLE=\"background:black\"> </TD></TR>\n";
echo " </TABLE>\n";
}
?>
</TD>
<TD WIDTH=20 STYLE="background:black"> </TD>
</TR>
</TABLE>
<? include ('../Footer.inc') ?>