Controller
public function addemployee()
{
$config['upload_path'] = './images/employee/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('include/headerforms');
$this->load->view('include/aside');
$this->load->view('template/forms/employeeforms',$error);
$this->load->view('include/footerforms');
}
else
{
$data = array('upload_data' => $this->upload->data('userfile'));
$data = [
'userfile' => './images/employee/' . $file['file_name'],
'userfile' => $this->input->post('userfile'),
'firstname' => $this->input->post('firstname'),
'firstname' => $this->input->post('firstname'),
'middlename'=> $this->input->post('middlename'),
'lastname'=> $this->input->post('lastname'),
'company'=> $this->input->post('company'),
'department'=> $this->input->post('department'),
'position'=> $this->input->post('position'),
'address'=> $this->input->post('address'))
];
$this->ci_db_model->addemployee($data);
this portion is connect to my database
$this->session->set_flashdata('message','New image has been added..');
$this->load->view('include/header2');
$this->load->view('include/aside');
$this->load->view('template/employee');
$this->load->view('include/footer2');
}
}
View
<!-- Name -->
<?php echo form_open_multipart('home/addemployee'); ?>
<div class="box-body">
<div class="form-group">
<label for="exampleInputFile">Photo</label>
<input type="file" name"userfile" id="exampleInputFile" required>
</div>
<div class="row">
<div class="col-xs-4">
<input name="firstname" type="text" class="form-control" placeholder="First Name" required>
</div>
<div class="col-xs-4">
<input name="middlename" type="text" class="form-control" placeholder="Middle Name" required>
</div>
<div class="col-xs-4">
<input name="lastname" type="text" class="form-control" placeholder="Last Name" required>
</div>
</div>
<input type="submit" name="submit" class="btn btn-primary pull-right" value="Submit">
<?php echo form_close(); ?>
Programming language : PHP Codeigniter server: XAMPP
I'M BEGINNER!!
Question: How to upload image into database?
When I click the submit button there an error "You did not select a file to upload.".
What wrong with my code?
THANKS IN ADVANCE PLEASE HELP ANYONE.