php returning FALSE from private function in another function -


My Codeigniter controller has the following private functions that validates the file upload.

  Personal function Avatar_file_validation () {$ config ['upload_path'] = './uploads/avatars/'; $ Config ['allowed_types'] =' jpg | PNG '; $ Config ['overwrite'] = true; // Overwrite user avatar $ config ['max_size'] = '800'; // $ KB in this- & gt; Load-> Library ('upload', $ config); If (! $ This-> upload-> do_upload ('avatar_upload')) {$ error_data = array ('error' => $ this-> upload-> display_errors ()); $ This- & gt; Avatar_view ($ error_data); // Load View Refund FALSE; }}   

If there is an error in uploading then I want to stop this function on

  function upload_over () {// something Code if ($ _ files) ['Entry_upload'] ['Error']! == 4) // If the file has been added to the field file {$ this- & gt; Avatar_file_validation (); // if return FALSE stop code} // code is released: adds data to the database, redirects}   

However the function continues even while returning false. This only works when I use the whole code in 1 function, but I have to separate them because I am using upload verification in multiple functions. What am I doing wrong here?

expression return false; is applicable only for the function avatar_file_validation () . If you want to stop the code in upload_avatar () , then when the upload is unsuccessful, you should see the output of avatar_file_validation () and if it is for FALSE Equal , come back with that function too. For example:

  function upload_over () {// some code if ($ _ FILES ['entry_upload'] ['error']! == 4) // If the file has been added to the field file (if (! $ This-> avatar_file_validation ()) // Return returns FALSE stop code FALSE;} // Code continues: Adds data to database, redirects}    

Comments