-1

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);
}
Pradeep
  • 9,667
  • 13
  • 27
  • 34
ishfaq khattak
  • 186
  • 2
  • 14

3 Answers3

1

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 }?>
Pradeep
  • 9,667
  • 13
  • 27
  • 34
  • Thankyou so much sir for your effort but it gives again error like this GET http://localhost/jageerx/assets/images/House28278954_957081961107785_391331158313648576_n.jpg 404 (Not Found) – ishfaq khattak Jul 06 '18 at 13:26
  • 1
    and also `$image` variable should have `/` after the `House` should be like this `House/28278954_957081961107785_391331158313648576_n.jpg` Currently it is like this `House28278954_957081961107785_391331158313648576_n.jpg` change it when adding to database – Pradeep Jul 06 '18 at 13:26
  • i think u got the idea – Pradeep Jul 06 '18 at 13:28
  • did u check my answer? is it helpful ? – Pradeep Jul 06 '18 at 14:36
  • if my answer helps you pls don't hesitate to check it as green – Pradeep Jul 07 '18 at 02:48
1

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

Community
  • 1
  • 1
mr_nobody
  • 356
  • 2
  • 4
1

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">
Muhammad Mudassar
  • 157
  • 1
  • 2
  • 10