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>