如果原始img不可用,则显示默认img


Show default img if original not available

如果图像原始图像不在图像文件中,我将尝试显示默认图像(coming_soon.png)。我尝试过互联网上的不同方法,但都不起作用。有人能帮忙吗。感谢

<img src="<?php fetchdir($php); ?>thumbnail.php?file=<?php echo $row['ImageFile']; ?>&amp;width=468&amp;height=309&amp;dir=product" />

我有一个CMS,它有一个类似的设置:一个处理缩略图创建的类,以及一个实例化该类、重新调整上传大小并将其保存到缩略图目录的脚本。这个脚本是这样调用的:

thumb.php/upload.jpg/400/300/contain

在您的实例中,您可以添加另一个参数,即默认图像的文件名。所以在我的情况下,我可以有这样的东西:

function get_thumbnail($filename, $width, $height, $type, $default) {
    if (file_exists($uploads_dir . $filename) {
        return sprintf('thumb.php/%s/%d/%d/%s', $filename, $width, $height, $type);
    }
    else {
        return $default;
    }
}

希望这能为你的场景指明正确的方向。

如果没有图像,只需将默认图像放入数据库中。

其中$sImagePath

if (!file_exists($sImagePath)) {
{
   // load default link
$sImagePath = 'default image file';
}

http://php.net/manual/en/function.file-exists.php