It's my first time using codeigniter. I am totally confused by uploading file in CI. I can insert the data, but the file won't be saved in database mysql
Here's my view - form
<form action="<?php echo base_url()."crud/do_insert";?>" method="POST" enctype="multipart/form-data">
<table>
<tr>
<td> Code </td>
<td><input type="text" name="code"></td>
</tr>
<tr>
<td> Name </td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td> price </td>
<td><input type="text" name="price"></td>
</tr>
<tr>
<td> Image </td>
<td><input type="file" name="image"></td>
</tr>
</table>
<input type="submit" name="insert" value="insert">
And here's my controller
public function do_insert(){
$code = $_POST['code'];
$name = $_POST['name'];
$price= $_POST['price'];
$image= $_FILES['image'];
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = 300;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$this->load->library('upload', $config);
$image = $this->upload->data();
$data_insert = array('code' => $code,
'name' => $name,
'price' => $price,
'image' => $image['file_name']
);
$res = $this->m_barang->insertData('stuff', $data_insert);
if($res>=1){
redirect('crud/index');
}else{
echo "Failed";
}
}
Is it because I have $_POST and $_FILES that the file wont be inserted in database? Do I have to seperate between text form and upload form but still in one page?