Welcome Guest, Not a member yet? Register   Sign In
Output image from controller to view
#1

[eluser]yusufdestina[/eluser]
In my view I have this:
Code:
<img src="'.base_url().'serve/thumb/'.$gallery->gallery_id.'/'.$pic->pic_id.'" alt="" title="" />
Then in controller Serve:
Code:
&lt;?php

class Serve extends Controller {
    
    var $img;
    
    function Serve()
    {
        parent::Controller();
        $this->load->model('Gallery_model');
    }
    function thumb(){
        $gid = $this->uri->segment(3);
        $pid = $this->uri->segment(4);
        $gallery = $this->Gallery_model->get_gallery($gid);
        $pic = $this->Gallery_model->getPic($pid,$this->session->userdata('id'));
        $this->img = 'gallery/'.$gallery->gallery_dir.'/thumb/'.$pic->pic_link;
        if(is_file($this->img)){
            Header("Content-Type: image/jpeg");
            print file_get_contents($this->img);
        }else{
            Header("Content-Type: image/jpeg");
            print file_get_contents('public/gfx/thumbnotset.jpg');
        }
    }
}
?&gt;
$this->img is defined and the path to the image is correct, can't figure out what I'm missing here. tnx for ur help.
#2

[eluser]yusufdestina[/eluser]
Very weird, if I place the code from inside thumb function to the contsructor and then reroute
Code:
$route['serve/:any'] = 'serve';
everything works.
If anyone knows why please let me know




Theme © iAndrew 2016 - Forum software by © MyBB