无法从完整路径回显图像

时间:2019-01-31 03:48:50

标签: codeigniter filepath

我正在尝试显示路径“上传/配置文件”中的所有图像。虽然可以部分使用,但其中还包含“上载”目录中的“替代”占位符(参见图片)。换句话说,它正在显示数据库表中的所有图像:是否可以从“上载”文件夹中删除占位符,而只显示“ /个人资料”中的实际图像?

我的观点:

<?php foreach($main_model as $images): ?>  
<table class="GeneratedTable">  
<tr><td><img class="thumb" src="<?php echo base_url()."uploads/profile/".$images->imageName;?>" alt="" data-toggle="tooltip" title="" ></td></tr>
<?php endforeach; ?>
</table>

enter image description here

1 个答案:

答案 0 :(得分:0)

首先,使用file_exists()检查文件在目录中是否存在。如果是,则显示它。

<?php foreach($main_model as $images): ?>  
    <table class="GeneratedTable"> 

      <?php $image = $images->imageName ? $images->imageName : '';
      $file_with_path = base_url('uploads/profile/'. $image);
      if(!empty($image) && file_exists($file_with_path )):?> 

      <tr><td><img class="thumb" src="<?php echo base_url()."uploads/profile/".$images->imageName;?>" alt="" data-toggle="tooltip" title="" ></td></tr>
<?php endif; endforeach; ?>
    </table>