I looked for this in Google and different answers on stackoverflow. And probaly there is an good answer in them but still i don't get how i can implent it in my own code.
I got my own public function to upload an image, but now i want it to be optional. At this moment someone needs to upload an file to pass the validation, how can i make this optional?
my function:
public function _do_upload_image()
{
$config['upload_path'] = './company_images/';
$config['allowed_types'] = 'jpg|jpeg|png';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
$this->form_validation->set_message('_do_upload_image', $this->upload->display_errors());
}
else
{
$this->_upload_data = $this->upload->data();
}
}
Thanks in advance
--edit--
For other people, the answer worked and i gave my file_name an other name when there was no image uploaded. It looks like this:
public function _do_upload_image()
{
$config['upload_path'] = './company_images/';
$config['allowed_types'] = 'jpg|jpeg|png';
$returnArr = array();
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
$returnArr = array('file_name' => 'leeg.jpg');
}
else
{
$returnArr = $this->upload->data();
}
$this->_upload_data = $returnArr;
}