I've put together some code to search through a directory and for all the jpg images it finds, display thumbnails and my required iptc and exif info. The problem is that I have many, many directories of photos and as it is I need an index.php file for each one. My directories are named by month and year; "1401" for January 20014, "1402" for Feb etc. and I have a set of shortcut images for each one called "1401.jpg", "1402.jpg" etc. so I use this code for users to nagivate to other directories where $shortcut has the values of 1401, 1402 etc:
echo("<a href=\" . $path . $shortcut . "\"><img src=\"shortcutimages/" . $shortcut . "\"></a>");
I'd love to allow users to navigate in a similar way without needing multiple index.php files. I would guess the best way is as follows:
On a mouseclick on a link like above, the main php (similar to below) should be re-run, replacing what's currently displayed on the screen but with new value for $dir replaced with something like $dir="../" . $shortcut; Is this the way to do it? As a newbie I apologise if this is really simple but as it is I can't seem to work it out.
thanks in advance for your help,
Sivadas
$dir="."; // or other folder path of choice!
$jpgcount=0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($image = readdir($dh)) !== false)
{
if (preg_match("/.jpg/", $image)) // only use .jpg files
{
$image=$dir . "/" . $image;
$exif = exif_read_data($image, 0, true);
$exif_name = $exif['FILE']['FileName'];
if(isset($exif['EXIF']['DateTimeOriginal']))
{
$timestamp = $exif['EXIF']['DateTimeOriginal'];
}
else
{
$timestamp = "1971:01:01 01:01:01"; // puts in a datestamp if one doesnt exist
}
$datename[] = $timestamp . $exif_name; // create array of date+name to allow sorting by date then retrieval of date ordered names once datestamp is removed
$jpgcount++; // counts number of jpgs in folder
}
}
sort($datename); // sort date+name array by date
for($c=0; $c<$jpgcount; $c++)
{
$image = pythonslice("$datename[$c]","19:"); // function strips off the datestamp (1st 19 characters) to leave the filename (taken from www.php.net/manual/en/function.substr.php slow at acedsl dot com)
$image=$dir . "/" . $image;
$size = getimagesize("$image", $info);
echo("<tr><td valign=top><A href=" . str_replace(' ', '%20', $image) ."> <IMG border=0 src=showthumb.php?image=" . str_replace(' ', '%20', $image) ."></A><td><td valign=top><font size=-1 face=\"Arial Narrow\">"); // get thumbnail and link to full image
show_metadata($image,$info); // function to display all required metadata
echo "</font></td></tr>";
}
closedir($dh);
}
}