dsnm64969 2011-02-13 02:41
浏览 21
已采纳

将EXIF标题添加到PHP库

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);
    }
  }
?>
  • 写回答

1条回答 默认 最新

  • doumu4916 2011-02-13 03:10
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line