-1

I am using a WAMP server, and I want to upload images in the database using CI.The image variable in database is of blob datatype. My question's as follows: 1) How to store the image instead of the file name and what datatypes should I use? 2) How to retrieve images from the DB?

my controller

public function index()
    {

    $this->load->model('contact_model');

    if ($this->input->post('upload')) {

    $data['logo_name']= $this->input->post('name');
    $data['logo_image']=$_FILES['userfile']['name'];


    if($this->contact_model->do_upload()) {

    echo $this->upload->display_errors();

    }else {

    $this->contact_model->Save_image($data);

        }
     }
        $data['getlogo']=$this->contact_model->getlogo();
        $this->load->view('templates/header',$data);
  }

my model

  function do_upload() {

$this-> gallery_path=realpath( APPPATH.'./uploads');

    $config = array( 
        'allowed_types' => 'jpg|png|bmp', 
        'upload_path'=>$this->gallery_path, 
        'max_size'=>2000
    );

    $this->load->library('upload',$config);

    if ($this->upload->do_upload()) {

        echo "Upload success!";         
        $image_data=$this->upload->data();
    }
    else 
        {
            echo "Upload failed!";
            echo $this->upload->display_errors();
        }

}  

    function getlogo(){

    $this->db->where('logo_id',3);
    return $this->db->get('logo');
}
function save_image($data){


    $q= $this->db->insert('logo', $in);
    return $q;
    }

my view

<?php foreach ($getlogo->result() as $row){ ?>
                <a href="#" style="padding-right:1px">
                <img src="<?php echo base_url();?>/application/uploads/<?php echo $row->logo_image;}?>"
                height="200px" width="500px" /></a>
M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
Arul
  • 111
  • 1
  • 2
  • 9
  • 1
    http://www.techcubetalk.com/2009/01/tutorial-on-how-to-store-images-in-mysql-blob-field/ – Muhammad Zeeshan Dec 11 '13 at 06:21
  • possible duplicate of [CodeIgniter: Storing an image in the database?](http://stackoverflow.com/questions/2775284/codeigniter-storing-an-image-in-the-database) – zzlalani Dec 11 '13 at 06:34

1 Answers1

1

follow this for saving file to blob

and use

<img src="data:image/jpeg;base64,<?php echo base64_encode($image['file_data'])?>'"/>

for displaying image

Dirgh
  • 507
  • 4
  • 13