In my Codeigniter controller have the following private function which validates file uploads.
private function avatar_file_validation()
{
$config['upload_path'] = './uploads/avatars/';
$config['allowed_types'] = 'jpg|png';
$config['overwrite'] = TRUE; //overwrite user avatar
$config['max_size'] = '800'; //in KB
$this->load->library('upload', $config);
if (! $this->upload->do_upload('avatar_upload'))
{
$error_data = array('error' => $this->upload->display_errors());
$this->avatar_view($error_data); //loads view
return FALSE;
}
}
if an error occurs in uploading I want to stop this function from continuing
function upload_avatar()
{
//some code
if($_FILES['entry_upload']['error'] !== 4) //if file added to file field
{
$this->avatar_file_validation(); //if returns FALSE stop code
}
//code continues: adds data to database, redirects
}
However the function continues even when returning false. It works only when I use the entire code in 1 function but I need to separate them as I'll be using the upload validation in multiple functions. What am I doing wrong here?