Reputation: 7965
I followed this tutorial on how to upload a photo in a codeigniter folder: http://codeigniter.com/user_guide/libraries/file_uploading.html
Can anybody tell me how can I store the path of the photo I just uploaded in my db?
Let's say have table called photo_paths
thanks in advance
Upvotes: 0
Views: 761
Reputation: 15642
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.
Upvotes: 0
Reputation: 3217
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);
Upvotes: 1