0

I have the following code now, and I want to simply add the EXIF Title data where the "CAPTION" text is. How do I do that? I know how to get the data, but I'm not sure how to add it to the "foreach" loop I already have going.

<?php
$path = "./images/bettydew/";
$file_array = array ();
readThisDir ( $path, &$file_array );

echo '<ul class="gallery">';
foreach ( $file_array as $file )
{
  if (strstr($file, "png")||strstr($file, "jpg")||strstr($file, "bmp")||strstr($file, "gif"))
  {
    echo '<li><a href="javascript:void(0);"><img src="'.$file.'" alt="'.$file.'"/></a></li>';
  }
}
echo '</ul>';

  function readThisDir ( $path, $arr )
  {
    if ($handle = opendir($path)) 
    {
        while (false !== ($file = readdir($handle))) 
        {
            if ($file != "." && $file != "..") 
            {
              if (is_dir ( $path."/".$file ))
              {
                readThisDir ($path."/".$file, &$arr);
              } else {
                $arr[] = $path."/".$file;
              }  
            }
        }
        closedir($handle);
    }
  }
?>
steve
  • 688
  • 6
  • 13
  • 32
  • SO readers: this question implicitly refers to this question: http://stackoverflow.com/questions/4981632/php-dynamic-gallery-problem/4981887#4981887 – jpwco Feb 13 '11 at 04:11

1 Answers1

0

Replace the foreach loop with this:

foreach ( $file_array as $file )
{
  if (strstr($file, "png")||strstr($file, "jpg")||strstr($file, "bmp")||strstr($file, "gif"))
  {
   list($width, $height) = getimagesize($file);
   $info = exif_read_data($file);           
   echo '<li><a href="javascript:void(0);"><img src="'.$file.'" width="'.$width.'" height="'.$height.'" alt="'.$file.'"/></a>'.$info['Title'].'</li>';
  }
}

this code is my answer to Steve's other SO answer @Steve - Please try harder.

Community
  • 1
  • 1
jpwco
  • 883
  • 1
  • 8
  • 15
  • I need to, for real! This one is a bit of a rush, but I'm working on it. I just got it to load from a php?name= so that's good for me now :) So much to learn, so little time... Thanks again (for the precious crack.) – steve Feb 13 '11 at 03:12