一个php页面应该显示一个缩略图,但却显示了一个破碎的图像


A php page should be displaying a thumbnail, but instead shows a broken image

我正在尝试制作一个基本的图片库,我在这里找到了一个教程:http://webcheatsheet.com/php/create_thumbnail_images.php

然而,使用这个代码只是让我在网页上的缩略图应该是一个破碎的图像。缩略图确实存在,文件权限也很好,所以这不是问题。我确实对函数做了一点修改,所以我想知道这是不是问题所在。

这是我修改的generate_gallery()版本。

function generate_gallery($basePath) {
        $pathToThumbs = $basePath . ".thumbs/";
        $output = "<table cellspacing='"0'" cellpadding='"2'" width='"500'">";
        $output .= "<tr>";
        // open the directory
        $dir = opendir($pathToThumbs);
        $counter = 0;
        // loop through the directory
        while (false !== ($fname = readdir($dir))) {
            // strip the . and .. entries out
            if ($fname != '.' && $fname != '..') {
                $output .= "<td valign='"middle'" align='"center'"><a href='"{$basePath}{$fname}'">";
                $output .= "<img src='"{$pathToThumbs}{$fname}'" border='"0'" />";
                $output .= "</a></td>";
                $counter += 1;
                if ($counter % 4 == 0) {
                    $output .= "</tr><tr>";
                }
            }
        }
        // close the directory
        closedir($dir);
        $output .= "</tr>";
        $output .= "</table>";
        echo $output;
    }

另外,这是它生成的页面中的HTML。(提前为糟糕的格式道歉。顺便提一下,我如何让PHP将HTML放在新行和其他东西上?)文件夹中有一个鸭子的测试图像,所以鸭子的缩略图应该出现。然而,我得到的却是一张破碎的照片。

<html>
<head>
    <meta charset="UTF-8">
    <title>20141120.1130</title>
</head>
<body>
    <a href="index.php">Back to Index</a><br>250-ducks.png<br><table cellspacing="0" cellpadding="2" width="500"><tr><td valign="middle" align="center"><a href="/mnt/ddcs_a/AEMP/Screens/20141120.1130/250-ducks.png"><img src="/mnt/ddcs_a/AEMP/Screens/20141120.1130/.thumbs/250-ducks.png" border="0" /></a></td></tr></table>    </body>

在脚本中更改以下代码,

$pathToThumbs = $basePath . "/thumbs/";
$output .= "<td valign='"middle'" align='"center'"><a href='"{$fname}'">";
$output .= "<img src='"{$fname}'" border='"0'" />";

无需使用绝对路径