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

  • SEARCH
  • Home
  • 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 7068823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:22:15+00:00 2026-05-28T05:22:15+00:00

I looked for this in Google and different answers on stackoverflow. And probaly there

  • 0

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;
}
  • 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-05-28T05:22:16+00:00Added an answer on May 28, 2026 at 5:22 am

    If you mean you need to make your upload function optional then you can just do:

    
    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  = $this->upload->data();
        }
        return $returnArr; //just return the array, empty if no upload, file data if uploaded
    }
    
    

    Hope that makes sense

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all- I have looked this up on here and Google but none of
I've looked at this but it wasn't too much help. Maybe I didn't read
I've looked at this question: Select first instance only with XPath? But if I
I've been trying this for a bit now and have looked at other answers
I'm sure this has already been done, but Google isn't helping me - I'm
I've looked at this before and found javascript that works for me with Google
I have asked a question like this before, and the answer was great but
I don't believe this is possible, and searching on Google didn't yield any results,
I've looked this up a thousand times, and I always forget it, so, here
I looked at this example http://msdn.microsoft.com/en-us/library/bb399420.aspx and clicked on DataContext.CreateDatabase which brought me to

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.