Search code examples
phpcodeignitercodeigniter-2

How to get Image on browser from binary data in php


I have 1 column containing binary format data. I want to display that Image on browser and I am useing codeignater

My Model Code

function GetLogoById($Id)
    {
        $this->load->database();
        $query =  $this->db->query( "EXEC GetLogoById '$Id'" );
        $result = array();
        foreach ($query->result() as $row)
        {
            $result[] = array("Logo"=> $row->Logo);
        }
           return $result;
    }

My Controller Code:

public function GetLogoById()
    {
    $this->load->model('MyModel');
    $result = $this->MyModel->GetLogoById($Id);
    $result = base64_decode($result);

    echo $result;
}

It return Blank in browse. What I am missing....


Solution

  • try with this.

    $this->load->model('GetLogoById');
    
       $result = $this->mymodel->GetLogoById($CarrierId);
    
       header('Content-type: image/png');
       echo  $result[0]['Logo'];