Images with content-type like text / html, how to solve? [closed]

-1

I am doing a foreach in the controller to test if it is returning all images the problem is that the images do not appear because the content-type is like text / html, when I am using the index method of the controller no problem, all files included in html has its correct content-type, the error is also happening in css.

<?phpuseapp\models\Images;ClassHome{publicfunctionindex(){include'app/views/index.php';$images=newImages();foreach($images->all()as$key=>$value){echo'<imgsrc="app/views/imgs/'.$value->name.'">';
    }
  }

  public function add(){
    $name = $_FILES['imagem']['name'];
    $image = new Images();
    $image->setName($name);
    if($image->insert()){
      $image->upload();
    }
  }

  public function img(){
    include 'app/views/index.php';
    $images = new Images();
    foreach ($images->all() as $key => $value) {
      echo '<img src="app/views/imgs/'.$value->name.'">';
    }
  }
}
    
asked by anonymous 02.12.2017 / 22:52

1 answer

0

I think it's a typo as images are accessing this:

/Home/app/views/imgs/...

Instead of this:

/app/views/imgs/...

Correcting:

public function index(){
  include 'app/views/index.php';
  $images = new Images();
  foreach ($images->all() as $key => $value) {
    echo '<img src="../app/views/imgs/'.$value->name.'">';
  }
}

...

public function img(){
  include 'app/views/index.php';
  $images = new Images();
  foreach ($images->all() as $key => $value) {
    echo '<img src="../app/views/imgs/'.$value->name.'">';
  }
}
    
03.12.2017 / 01:35