Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:57:19+00:00 2026-06-07T10:57:19+00:00

In my Codeigniter controller have the following private function which validates file uploads. private

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:57:21+00:00Added an answer on June 7, 2026 at 10:57 am

    The expression return FALSE; only applies to the function avatar_file_validation(). If you want to stop the code in upload_avatar() when the upload fails, you should check the output of avatar_file_validation() and if it equals FALSE, return from that function as well.

    For example:

    function upload_avatar()
    {
        //some code
    
        if($_FILES['entry_upload']['error'] !== 4) //if file added to file field
        {
            if(!$this->avatar_file_validation()) //if returns FALSE stop code
                return FALSE;
        }
    
        //code continues: adds data to database, redirects
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using CodeIgniter and I have a controller which processes uploads using AJAX. The
I am using Codeigniter message library. In my controller I have the following code
I have 2 functions/methods in the same controller in CodeIgniter like this: public function
I have this function on my controller (Im using CodeIgniter) that reads the database,
I am trying to extend the CodeIgniter controller. I have created MY_Controller.php file, the
Fellow coders, i have a function in a codeigniter controller that accepts a couple
I have a problem right now with CodeIgniter : I use the REST Controller
How to call codeigniter controller function from view? When i call the function in
I have a small codeigniter controller. Below is the code class Example extends CI_Controller
I have the following controller and view. I am trying to learn jquery in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.