【发布时间】:2015-09-30 23:04:18
【问题描述】:
我已经寻找这个问题 3 天了 - 并尝试任何接近或相关的东西,看看我是否可以让它工作....
我正在使用 PHP 从 JPG 文件中提取 EXIF 标签
并在一个简单的鼠标悬停脚本中使用它,但这就是它崩溃的地方:
获取 EXIF 数据
foreach($images as $img){
$exif = exif_read_data($img, 0, true);
在我的测试过程中,我简化了变量名——我认为这没有必要,但这就是我现在的位置
$Ititle = $exif['IFD0']['Title'];
$Isubject = $exif['IFD0']['Subject'];
$Icomment = $exif['IFD0']['Comments'];
$m = "<p>Title: ".$Ititle."<BR>Subject: ".$Isubject."<BR>Comments: ".$Icomment."</p>";
echo $m;
这个 Echo $m 按预期工作了 Jpg 图像中的标题/主题/评论。
所以我有一个缩略图图像,使用鼠标悬停将大图像“preview1.2.3.4 ...”更改为您鼠标悬停的img ....并将<p>更改为正确的标题/主题/ cmets..
<img onmouseover="document.getElementById('exifdata<?echo $b;?>').innerHTML = '<?echo $m;?>'; preview<?echo $b;?>.src=img<?echo $p;?>.src" name="img<?echo $p;?>" src="<?echo $img;?>" style="float:left; margin-right:10px; Max-width: 100px; Max-height:100px; width:auto; height:auto;">
Img 和文本更改适用于翻转但
在<p> 中显示如下
标题:H.a.p.p.y..C.o.u.p.l.e..
主题:E.n.j.o.y.i.n.g..I.N..S.u.m.e.r....
评论:
这里是文本变化的DIV
<div style="width:680px; height:auto; overflow:hidden; background: rgba(66, 95, 149, 1);">
<p id='exifdata<?echo $b;?>'>testing
</p>
</div>
在通过这个innerHTML之后添加这些问号是什么?
还有整个 php 页面:*对不起,如果它很乱 - 我已经尝试了很多东西
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
header('Content-Type:text/html; charset=UTF-8');
$b = 1;
$blogs = array_filter(glob('./Content/*'), 'is_dir');
foreach($blogs as $entries){
/*
print "<br>";
print $entries;
print "<br>";
print "<p>Images</p>";
*/
#get all the JPG s in the blog folder
$images = array_filter(glob("$entries/*.JPG"));
#get Textblock and title txt files for verbage....
$textblock = file_get_contents("$entries/Textblock.txt");
$title = file_get_contents("$entries/Title.txt");
#get date for post
$PostDatestr = substr($entries,-8);
$PostDate = date("d M Y", strtotime($PostDatestr));
#Create Entry regardless of type:
?>
<div id="Notice">
<div id="Title"><h2><?echo $title;?></h2></div>
<section class="Wrapper">
<header class="Wrapper"><h1><?echo $PostDate;?></h1></header>
<article>
<?
#print the Blog post.... if one or less photos in DIR
if (count($images) <= 1){
#Don't use img tag if there are 0 images.
if (count($images) === 1){
?><img src="<?echo $images[0];?>" style="float:left; margin-right:10px; Max-width: 680px; Max-height:680px; width:auto; height:auto;">
<?
}
echo $textblock;
}
#print the Blog post.... if there is more than 1 photo in DIR
if (count($images) > 1){
#get info for each photo
?>
<div class="thumbnails" style="width;100%; height:auto; display:block; overflow:hidden;">
<?
foreach($images as $img){
$exif = exif_read_data($img, 0, true);
$Ititle = $exif['IFD0']['Title'];
$Isubject = $exif['IFD0']['Subject'];
$Icomment = $exif['IFD0']['Comments'];
$m = "<p>Title: ".$Ititle."<BR>Subject: ".$Isubject."<BR>Comments: ".$Icomment."</p>";
echo $m;
#echo $exif===false ? "No header data found.<br />\n" : "Image contains headers<br />\n";
?>
<img onmouseover="document.getElementById('exifdata<?echo $b;?>').innerHTML = '<?echo $m;?>'; preview<?echo $b;?>.src=img<?echo $p;?>.src" name="img<?echo $p;?>" src="<?echo $img;?>" style="float:left; margin-right:10px; Max-width: 100px; Max-height:100px; width:auto; height:auto;">
<?
$p++;
$lastimg = $img;
}
?>
</div>
<br><br>
<div class="preview<?echo $b;?>" align="center" Style="width:640px; margin:0 auto; overflow:hidden;">
<img name="preview<?echo $b;?>" src="<?echo $lastimg;?>" style="float:left; margin-right:10px; Max-width: 680px; Max-height:680px; width:auto; height:auto;" alt=""/>
</div>
<div style="width:680px; height:auto; overflow:hidden; background: rgba(66, 95, 149, 1);">
<p id='exifdata<?echo $b;?>'>testing
</p>
</div>
<?
}
?>
</article>
</Section>
</div>
<?
$b++;
}
?>
</body>
</html>
【问题讨论】:
-
我的直接想法是“happy couple”和“enjoying...”是 16 位字符串被解释为 8 位字符串。鉴于“标题”、“主题”和“评论”应该出现,我建议查看
$m = "<p>Title: ".$Ititle."<BR>Subject: ".$Isubject."<BR>Comments: ".$Icomment."</p>";的字符处理 -
谢谢 - 有没有办法以 16 位回显,或将变量转换为 8 位?
-
请确认
$Isubject = $exif['IFD0']['Subject'];的字符串长度是您预期的两倍。这将确认字符编码问题是问题的基础,并允许以更少的猜测工作获得适当的答案。 -
好吧 strlen($Isubject) 显示 26,印有 � 的字符串是 26,没有 �,应该是 12 - 几乎一半....
标签: javascript php html innerhtml exif