本文介绍了PHP EXIF数据不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP的新手,他从 http://www.techrepublic.com/article/create-a-dynamic-photo-gallery-with-php-in-three-steps/会生成一张图像表目录以及一些随附的EXIF数据.唯一的问题是该代码未显示EXIF数据.即使是原始源代码也会发生这种情况.我对发生的事情的最佳猜测是,原始源代码中的某些东西已经过时和过时,并且不再受现代PHP的支持.我已经确保我的服务器已启用EXIF.

I am new to PHP, and adapting a script from http://www.techrepublic.com/article/create-a-dynamic-photo-gallery-with-php-in-three-steps/ which generates a table of images in a directory along with some accompanying EXIF data. The only problem is that the code has not display the EXIF data. This happens with even the original source code. My best guess of what is happening is that something in the original source code is old and outdated, and no longer supported by modern PHP. I have made sure that my server has EXIF enabled.

代码如下:

<table>
<?php
// define directory path
$dir = "path/to/directory";

// iterate through files
// look for JPEGs
if (is_dir($dir)) {
  if ($dh = opendir($dir)) {
    while (($file = readdir($dh)) !== false) {
      if (preg_match("/.jpg/", $file)) {

        // read EXIF headers
        $exif = exif_read_data($file, 0, true);

        // get image
        echo "<tr><td rowspan='3'><img src='$dir/$file'></td>";

        // get file name
        echo "<th>Title</th><td>" . $exif['FILE']['FileName'] . "</td></tr>";

        // get timestamp
        echo "<tr><th>Year</th><td>"  . $exif['IFD0']['DateTime'] . "</td></tr>";

        // get image dimensions
        echo "<tr><th>Description</th><td>" . $exif['IFD0']['Comments'] . "</td></tr>";

      }
    }
    closedir($dh);
  }
}
?>
</table>

编辑:我还会收到以下错误日志:

I also get the following error logs:

20160815T185355: benxd.me/art/gallery.php 
PHP Warning:  exif_read_data(): Unable to open file in /hermes/walnaweb01a/b893/pow.hdemoras/htdocs/benxd/art/gallery.php on line 21 
PHP Warning:  exif_read_data(): Unable to open file in /hermes/walnaweb01a/b893/pow.hdemoras/htdocs/benxd/art/gallery.php on line 21 
PHP Warning:  exif_read_data(): Unable to open file in /hermes/walnaweb01a/b893/pow.hdemoras/htdocs/benxd/art/gallery.php on line 21 
PHP Warning:  exif_read_data(): Unable to open file in /hermes/walnaweb01a/b893/pow.hdemoras/htdocs/benxd/art/gal 

在我的代码行21中是$exif = exif_read_data($file, 0, true);

In my code line 21 is $exif = exif_read_data($file, 0, true);

推荐答案

尝试显式添加完整路径和部分列表:

Try explicitly adding the full path and the list of sections:

$exif = exif_read_data($dir . $file, "FILE,COMPUTED,ANY_TAG,IFD0,THUMBNAIL,COMMENT,EXIF", true);

来源: http://php.net/manual/zh/function.exif-read-data.php

这篇关于PHP EXIF数据不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 02:44