title: Codeigniter upload optional
body: <p>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.</p>
  
  <p>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?</p>
  
  <p>my function:</p>
  
  <pre><code>public function _do_upload_image()
  {
      $config['upload_path'] = './company_images/';
      $config['allowed_types'] = 'jpg|jpeg|png';
  
      $this-&gt;load-&gt;library('upload', $config);
  
      if (!$this-&gt;upload-&gt;do_upload())
      {
          $this-&gt;form_validation-&gt;set_message('_do_upload_image', $this-&gt;upload-&gt;display_errors());
      }
      else
      {
          $this-&gt;_upload_data = $this-&gt;upload-&gt;data();
      }
  
  }
  </code></pre>
  
  <p>Thanks in advance</p>
  
  <p>--edit--</p>
  
  <p>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:</p>
  
  <pre><code>public function _do_upload_image()
  {
      $config['upload_path'] = './company_images/';
      $config['allowed_types'] = 'jpg|jpeg|png';
      $returnArr = array();
  
      $this-&gt;load-&gt;library('upload', $config);
  
      if (!$this-&gt;upload-&gt;do_upload())
      {
          $returnArr = array('file_name' =&gt; 'leeg.jpg');
      }
      else
      {
          $returnArr = $this-&gt;upload-&gt;data();
      }
  
      $this-&gt;_upload_data = $returnArr;
  }
  </code></pre>