i am trying to rename an image file and save the file location in database. i am having problem problem with it, as i want to name the file as the id of the table row i am inserting in. after uploading and inserting i want to see my table as like this:
----------------------------------------
| id | name | category | image |
----------------------------------------
| 1 | foo | category | uploads/1.jpg |
----------------------------------------
the id field is auto incremented. here is my code for it:
function service()
{
$con=$this->do_upload();
$id=mysql_insert_id();
$data=array(
'name'=>$this->input->post('name'),
'category'=>$this->input->post('category'),
'image'=>'uploads/'.$id.$con['file_ext'];
);
$query=$this->db->insert('table',$data);
return $query;
}
this is not the correct way and as assumed the file is not saved in the database as wanted.instead of saving it as 'uploads/1.jpg' it is saved as 'uploads/0.jpg'.
can any one provide me the right convention to do it?
n.b. i am using codeigniter 2.1.0 and mySQL database.