views:

38

answers:

2
+2  A: 

This assumes you have an Images table.

Configure the file upload as follows:

 $config['upload_path'] = './images/';
 $config['allowed_types'] = 'gif|jpg|png';
 $config['max_size']    = '1000000';
 $config['overwrite'] = TRUE;
 $config['remove_spaces'] = TRUE;
 $config['encrypt_name'] = FALSE;

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

Then on successful upload insert the file information into the database.

$insert_data = array(
'id_fk' => $this->input->post('page_id'),
'imgfilename' => $upload_info['file_name'],
'imgfilepath' => $upload_info['file_path']
);
$this->db->insert('images', $insert_data);

$upload info is retrived from the file_uploader class on successful upload using the following:

$upload_info = $this->upload->data();

If you want to see exactly what is returned:

echo var_dump($upload_info);
DRL
Thanks... I did what you suggested but I get two errors in the last line... $this->db->insert('images', $insert_data) one saying "Message: Undefined property: Upload::$db " and another saying "Fatal error: Call to a member function insert() on a non-object "
rabidmachine9
Ensure that the database class is loaded (either in the controller or in your config/autoload.php {in here $autoload[‘libraries’]}), the upload was successful, and that the $upload_info is being populated.
DRL
that fixed everything...thanks!
rabidmachine9
A: 

For me, since most of my uploaded images are about the same thing (for example, product images) I might just store the filename (e.g. productshot1.jpg) in the database, since I know where it is anyway (for example, I might keep all product images in "/images/products/"). That way if you need to change something later, it's not so difficult.

Matthew