【发布时间】:2013-05-16 22:53:33
【问题描述】:
我有一个产品组合,每个产品组合都有一个图像,如果数据库字段“图像”为空,我正在加载通用图像,但如果在某些情况下该字段具有图像值但文件不存在我也想使用通用图像,我尝试使用下面的代码,但仅适用于空字段:
<div class="wrapper"><a href="store.php?url=<?php echo $row->url ?>"><img src="images/stores/category/
<?php
if (empty($row->image) or file_exists($row->image)==false) {
echo 'generic.jpg';
}else{
echo $row->imagen; }?>" alt="<?php echo $row->seo ?>"/></a></div>
</div>
<?php } ?>
感谢您的宝贵时间!
【问题讨论】:
-
这是一个错字
$row->imagen? -
使用
is_file而不是file_exists。如果路径是目录,最后一个也将返回 true。
标签: php file-exists