我是 PHP 新手,正在改编http://www.techrepublic.com/article/create-a-dynamic-photo-gallery-with-php-in- Three-steps/ 中的脚本,该脚本会生成一个图像表一个目录以及一些附带的 EXIF 数据。唯一的问题是代码没有显示 EXIF 数据。即使是原始源代码也会发生这种情况。我对正在发生的事情的最佳猜测是原始源代码中的某些内容已经过时并且不再受现代 PHP 支持。我已确保我的服务器启用了 EXIF。
这是代码:
<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>" …Run Code Online (Sandbox Code Playgroud)