UPDATE:
(The code for thumbnails.php is the same, and still required. See above.)
Updated test page: http://ci-pro.com/truthandlies/images/index.phpPHP Code:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Image Browser</title>
<style type="text/css">
ul.dirlist, ul.dirlist li {
list-style-type: none;
}
a {
color: #0000FF;
}
div.border {
border-left-style: solid;
border-bottom-style: solid;
border-color: #000066;
border-width: thin;
}
</style>
</head>
<body bgcolor="#000000" text="#0000FF">
<?php
$page = substr($_SERVER['SCRIPT_NAME'],(strrpos($_SERVER['SCRIPT_NAME'],"/")+1));
function checkDir($c,$skipimages=0) {
echo('<div class="border"><ul class="dirlist">');
$d = opendir($c);
while($f = readdir($d)) {
if(strpos($f, '.') === 0) continue;
$ff = $c . '/' . $f;
if (strpos(strtolower($f), '.jpg') !== FALSE && $skipimages != 3) {
if ($skipimages != 1) {
$fff = '<img src="thumbnail.php?image='.urlencode($ff).'" border="">';
echo('<a href="' . $ff . '">' . $fff . '</a>'."\n");
}
else {
$n++;
}
}
if(is_dir($ff)) {
$fflink = $ff;
if (substr($ff,0,2) == "./") $fflink = substr($ff,2);
echo '<li><a href="'.$page.'?'.urlencode($fflink).'"'."><b>$f</b></a></li>\n";
global $dir;
if ($ff == $dir) $skipimagesnext = 0;
else $skipimagesnext = 1;
if ($skipimages == 2) $skipimagesnext = 2;
if ($skipimages == 3) $skipimagesnext = 3;
checkDir($ff,$skipimagesnext);
}
}
if ($n != "") echo "($n images)\n";
echo('</ul></div>');
}
$uri = explode("?",$_SERVER['REQUEST_URI'],2);
$dir = urldecode($uri[1]);
if(is_dir($dir)) {
checkDir($dir);
if(strpos($dir,"/") !== FALSE) {
$updir = "?".substr($dir,0,strrpos($dir,"/"));
echo '<a href="'.$page.$updir.'">^up^</a><br>'."\n";
}
echo '<a href="'.$page.'">Top</a>'."\n";
}
else if($dir == "all") checkDir(".",2);
else if($dir == "none") checkDir(".",3);
else checkDir(".");
echo '<a href="'.$page.'?none">Collapse All</a>'."\n";
echo '<a href="'.$page.'?all">Expand All</a>'."\n";
?>
</body>
</html>
Everything works.
Images and subdirectories display within directories.
Added "expand all" and "collapse all" links.
Added numbers showing how many images a non-expanded subdirectory contains.
Did some work on the layout so it is visually clear. (And the numbers work now.)
No work on making the images pre-rendered. Not sure if this makes sense. (doing an if and checking if the image has an existing thumbnail and if not, creating one, seems like a bit much at the moment. Maybe....)
No support for non-jpegs. Not yet. Easy later, though.
I'm really liking it.
