2

我有一个脚本,它从存储在给定目录中的照片中提取 Exif 数据,然后在网页上显示带有 exif 信息的图像。

这是检索 exif 数据的脚本部分,此示例是硬编码图像:

    $Image = 'original/raleighbike.JPG';

    echo "$Image";

    $exif = exif_read_data($Image, 0, true);

这有效并显示 exif 数据。(“回声”只是为了验证是否正在设置正确的图像以在下一部分中检索 - 这是我遇到问题的地方。)

我现在使用相同的脚本从先前脚本中上传并存储在同一目录中的图像中获取 exif。上传脚本设置一个包含图像名称和位置的变量 ($Image9),exif 提取脚本现在如下所示:

$Image = $Image9;

echo "$Image";

$exif = exif_read_data($Image, 0, true);

我遇到的问题是“回声”打印了正确的图像名称和位置,但 exif 数据为空并且错误日志显示:

[02-Apr-2013 18:45:29 America/Chicago] PHP Warning:  exif_read_data() [<a href='function.exif-read-data'>function.exif-read-data</a>]: Unable to open file in /home2/webi8726/public_html/domain.com/sqlsidebar/displayexif.php on line 23

第 23 行是上面引用部分的最后一行。

我不明白为什么打开硬编码图像没有问题,但无法打开由变量标识的图像 - 即使变量包含正确的信息并且指向同一个硬编码文件。

任何人都可以提出问题发生的原因。


好的-今天又玩了一些,这就是我发现的。

1 - 在上传和存储 jpg 的脚本中,我将它设置的变量更改为 $photo。$photo 应该包含 jpg 的名称及其存储的目录。我还设置了一个名为 $thumb 的不同变量,其中包含由上传脚本创建和存储的 jpg 缩略图的名称和位置。

2 - 我更改了 exif 提取脚本以使用 $photo 变量创建一个名为 $Image 的变量,该变量在 exif 提取后在脚本中的各个点使用 - 例如获取和显示图像以及将图像详细信息存储在sql数据库。

3 - 我设置了一些“回声”命令来验证变量的内容,以及确认文件是否存在。

这是现在的脚本代码:

    $Image = $photo;

    echo "$photo";

    echo $Image;

    echo file_exists($Image) ? 'ok' : ' image file not found';

    echo file_exists($photo) ? 'ok' : '  photo file not found';

    echo $thumb;

    echo file_exists($thumb) ? 'ok' : '  thumb file not found';

    $exif = exif_read_data($photo, 0, true);

生成的回显字符串显示以下内容

original/raleighbike.jpg - content of variable $photo (correct)
original/raleighbike.jpg - content of variable $Image (correct)
image file not found - when checking for the file in $Image (incorrect, file does exist)
photo file not found - when checking for the file in $photo (incorrect, file does exist)
thumb file not found - when checking for the file in $thumb (incorrect, file does exist)
thumbnail/thumb_raleighbike.jpg

因此,如果一个文件是硬编码的,那么脚本可以在物理上找到它,但是如果一个文件被指定为变量,脚本就找不到它们。

有没有人知道为什么会发生这种情况 - 我肯定不会是唯一遇到这个问题的人;-(

4

0 回答 0