Welcome Guest, Not a member yet? Register   Sign In
upload image using model/view/controller

I want to need help to upload image file.B'coz i had tried simply upload file but how to save that file in database table using model file.....

[eluser]Pascal Kriete[/eluser]
You need to upload it to a temporary spot on the disk first. Then you can do something like this:
// Get the image as 'text'
$image = file_get_contents('path/to/image.png');

$data = array(
    'name' => 'image.png',
    'contents' => $image

$this->db->insert('images', $data);

The contents field should be of the 'blob' or 'largeblob' type. Also, iirc file_get_contents reads the whole file into memory, so if you expect a lot of uploads you may want to consider creating a queue of sorts. And always check the file size to make sure you don't go over your memory limit.

Putting the file somewhere on the disk and just saving the path to the db is the solution I would use. It's faster.

or you can insert it after upload.

$config['upload_path'] = /path/to/file;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';
$this->load->library('upload', $config);


$data = array(
    'name' => $_FILES['userfile'][name],
    'type' => $_FILES['userfile'][type]

$this->db->insert('images', $data);
  echo $this->upload->display_errors('<p>', '</p>');    

Theme © iAndrew 2016 - Forum software by © MyBB