So far, always saved a path for the images in the database, but this time, I have to save the actual image in the database. I prepared a field for that in my table(longblob)
I have this code in my controller:
$insertWhat = array(
'dsrequestFileName1' => $this->input->post('dsrequestFileName1'),
'dsrequestFile1' => isset($_FILES['dsrequestFile1']['name'])? $_FILES['dsrequestFile1']['name'] : '',
'dsrequestFileName2' => $this->input->post('dsrequestFileName2'),
'dsrequestFile2' => isset($_FILES['dsrequestFile2']['name'])? $_FILES['dsrequestFile2']['name'] : ''
);
$now = date('Y-m-d-His');
$valid_extensions = array('gif', 'jpg', 'jpeg', 'png', 'bmp','');
if($insertWhat['dsrequestFile1'] !=""){
if (!in_array(end(explode('.', strtolower($_FILES['dsrequestFile1']['name']))), $valid_extensions)) {
$this->session->set_flashdata('wrongtype', '<p class=error>Wrong type of file has been uploaded! Only gif, jpg, bmp and png are allowed.</p>');
redirect('somepage/somefunctionHere');
}
$insertWhat['dsrequestFile1'] = str_replace(' ', '_',$insertWhat['dsrequestFile1']);
$insertWhat['dsrequestFile1'] = $now.$insertWhat['dsrequestFile1'];
}
$config['upload_path'] = 'somefolder/imagesfolder';
$config['allowed_types'] = 'gif|jpg|jpeg|bmp|png';
$config['max_size'] = '2048';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['file_name'] = $insertWhat['dsrequestFile1'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
// perform the upload
$this->upload->do_upload('dsrequestFile1');
$data = array('upload_data' => $this->upload->data('dsrequestFile1'));
// code that saves the insert data is irrelevant to the question, I can post it here if needed however.
However, this code only upload the image. What should I change here so I can save the image in the database. I don't want to upload the image if that is possible.
Nothing on this in CI manual unfortunately.