CodeIgniter Forums

Full Version: displaying blob data from db
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]junaids[/eluser]
Hi,
I am trying to display data from data base but getting an error. my function is,
<?php
Code:
function getpic($id){

     $query = $this->db->query("SELECT content FROM picture WHERE id = '$id';");
     if($query){
        $result = $query->result();
        foreach($result as $result){
           header("Content-type: image/jpg");
           print $result->$field;
        }
     }

}
}

my url is..
http://localhost/codeigniter32/index.php/shop/getpic/1
and i am getting the error
The image “http://localhost/codeigniter32/index.php/shop/getpic/1” cannot be displayed because it contains errors.

The url in this error points correctly to the controller and function ..any help????

El Forum

[eluser]Bhashkar Yadav[/eluser]
you need to set header for displaying image content like
Code:
header("Content-type: image/jpeg");

instead of

Code:
header("Content-type: image/jpg");

El Forum

[eluser]vitoco[/eluser]
i don't know where i's defined the $field var , so this
Code:
print $result->$field;
i think should be
Code:
print $result->content;

Saludos

El Forum

[eluser]junaids[/eluser]
@vitoco..ur advice works fine.