我现在有以下代码,我想简单地添加“CAPTION”文本所在的EXIF标题数据。我怎么做?我知道如何获取数据,但我不确定如何将它添加到我已经进行的“foreach”循环中。
<?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);
}
}
?>
答案 0 :(得分:0)
将foreach
循环替换为:
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 - 请更加努力。