I want to output an image that I've stored in MYSQL with file_get_contents("http://www.example.com/img.jpg")
in an HTML page. I have the following code but I'm stuck as to how to make this work. Right now, it displays gibberish or if I use header, a broken image. I'm using codeigniter:
Model:
public function img_get() {
$query = $this->db->query('SELECT * FROM imgtable');
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
}
return $data;
}
Controller:
class Site extends CI_Controller {
public function index() {
$this->load->model('img_model');
$data['row'] = $this->img_model->img_get();
$this->load->view('home_view', $data);
}
View:
<html>
<head>
<title>Homepage</title>
</head>
<body>
<h3>Insert the image url</h3>
<br>
<?php
foreach ($row as $r) {
echo $r->img . "<br />";
}
?>
</body>
</html>