douke9379
douke9379
2018-07-06 13:02
浏览 28
已采纳

如何在codeigniter中显示/显示图像?

I am trying to display the images of my Houses from the folder but it shows the error like this

http://localhost/jageerx/assets/images/House/assets/images/House28278954_957081961107785_391331158313648576_n.jpg

404 (Not Found)

My code is below

<?php
$PropertyType = "";
$image = "";
if($data != null)
{
foreach($data as $key=>$value)
{
    $PropertyType = $value['PropertyType'];
    $image=$value['HouseImage1'];
}
}
?>

the front-end code is this

 <img src="<?php echo base_url('assets/images/House/'. $image);?>" alt="tab1" class="img img-responsive"> 

folders hierarchy is mentioned below

This is the hierarchy of folders

this is the model function

public function SIngleHouseADD($houseID)
{
    $this->db->select('*');
    $this->db->from('housedetail');
    $this->db->where('HouseID', $houseID);
    //$qry = $qry->result_array();
    $query=$this->db->get();
    $resultArray = $query->result_array();
    return $resultArray;
    //return $qry;
}

this one is the controller

public function SingleProperty()
{
    //$HouseID = $_GET['id'];
    $this->load->model('SingleAddModel');
    $plots = $this->SingleAddModel->SIngleHouseADD($_GET['id']);
    $data = array();
    $data["data"] = $plots;
    $this->load->view('SinglePropertyDetail_view', $data);
}

图片转代码服务由CSDN问答提供 功能建议

我正在尝试从文件夹中显示我的房屋的图像,但它显示的错误是这样的

http:// localhost / jageerx / assets / images / House / assets / images / House28278954_957081961107785_391331158313648576_n.jpg

404(未找到)

我的代码在

 &lt;?php 
 $ PropertyType =“”; 
 $ image =  “”; 
if($ data!= null)
 {
foreach($ data as $ key =&gt; $ value)
 {
 $ PropertyType = $ value ['PropertyType']; 
 $ image =  $ value ['HouseImage1']; 
} 
} 
?&gt; 
   
 
 

前端代码是这个 \ n

 &lt; img src =“&lt;?php echo base_url('assets / images / House /'。$ image);?&gt;”  alt =“tab1”class =“img img-responsive”&gt;  
   
 
 

文件夹层次结构如下所述

这是模型函数

 公共函数SIngleHouseADD($ houseID)
 {
 $ this-&gt; db-&gt; select(  '*'); 
 $ this-&gt; db-&gt; from('housedetail'); 
 $ this-&gt; db-&gt; where('HouseID',$ houseID); 
 // $ qry  = $ qry-&gt; result_array(); 
 $ query = $ this-&gt; db-&gt; get(); 
 $ resultArray = $ query-&gt; result_array(); 
返回$ resultArray; 
  //返回$ qry; 
} 
   
 
 

这个是控制器

 公共函数SingleProperty()  
 {
 // $ HouseID = $ _GET ['id']; 
 $ this-&gt; load-&gt; model('SingleAddModel'); 
 $ plots = $ this-&gt; SingleAddModel-&gt;  SIngleHouseADD($ _ GET ['id']); 
 $ data = array(); 
 $ data [“data”] = $ plots; 
 $ this-&gt; load-&gt; view('SinglePropertyDetail_view',  $的数据);  
} 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doupang1917
    doupang1917 2018-07-07 20:09
    已采纳

    In base_url() you are passing assets/images/House/ the same path in $image, so it is duplicating path, I'll suggest you to first echo the results then use them in html. And for your Image you can use:

    <img src="<?php echo base_url().$image;?>" alt="tab1" class="img img-responsive"> 
    

    OR

    <img src="assets/images/House/<?php echo $image;?>" alt="tab1" class="img img-responsive">
    
    点赞 评论
  • dsds33222
    dsds33222 2018-07-06 13:22

    Hope this will help you :

    Since your $image variable already contains assets/images/House so should not be use in base_url() again

    Should be like this :

     foreach($data as $key=>$value) {
            $PropertyType = $value['PropertyType'];
            $image=$value['HouseImage1'];
        ?>
            <img src="<?php echo base_url().$image;?>" alt="tab1" class="img img-responsive"> 
    
        <?php }?>
    
    点赞 评论
  • duanbixia7738
    duanbixia7738 2018-07-07 10:37

    I don't know if this works best for you but when I add images or css in codeigniter I usually add them in the same level as my index.php so it goes like this!

    See screenshot. screenshot

    点赞 评论

相关推荐