title: multiple file upload and single file upload on same page using codeigniter
body: <p>I have tried to upload multiple files and profile pic on a single page but it does not work properly.</p>
  
  <pre><code>/** multiple file upload**/
  if (!empty($_FILES['attach_file']['name'])) {
      $upload = do_upload($_FILES, $folder);
      if (count($upload) &gt; 0) {
          foreach ($upload as $key =&gt; $status) {
              if ($status == 1) {
                  $form_data = array(
                      'user_id' =&gt; $user_id,
                      'image_name' =&gt; $key
                  );
                  $this-&gt;Providerfiles_model-&gt;insert($form_data);
              }
          }
      }
  }
  </code></pre>
  
  <p>I am using this code for multi file uploading but it doesn't work. It's uploading only one document.</p>
  
  <pre><code>/***profile pic uplod**/
  if ($_FILES &amp;&amp; $_FILES['file1']['name'] != "") {
      $folder = FCPATH . 'upload/';
      if ($this-&gt;upload-&gt;do_upload('file1')) {
          $image_data = $this-&gt;upload-&gt;data();
          $pic_data = array(
              'user_id' =&gt; $user_id,
              'title' =&gt; $image_data['file_name']
          );
          $this-&gt;profilepic_model-&gt;insert($pic_data);
          $image_id = $this-&gt;db-&gt;insert_id();
      }
  }
  </code></pre>
  
  <p>I am using this code for profile pic upload. It's working fine but when I upload multiple documents and profile pic together it's not working properly. Documents  will be saving in profile pic table and I am not able to find the solution for this.</p>
  
  <p>This is the function I am using for multiple file uploading in helper</p>
  
  <pre><code>/** do_upload() in helper**/
  function do_upload($files, $folder_name) {
      $return = array();
      $ci = &amp; get_instance();
      $cpt = count($files['attach_file']['name']);
      for ($i = 0; $i &lt; $cpt; $i++) {
          $image = $files['attach_file']['name'][$i];
          $config['file_name'] = $image;
          $_FILES['userfile']['name'] = $image;
          $_FILES['userfile']['type'] = $files['attach_file']['type'][$i];
          $_FILES['userfile']['tmp_name'] = $files['attach_file']['tmp_name'][$i];
          $_FILES['userfile']['error'] = $files['attach_file']['error'][$i];
          $_FILES['userfile']['size'] = $files['attach_file']['size'][$i];
          $ci-&gt;upload-&gt;initialize($config);
  
          if ($ci-&gt;upload-&gt;do_upload()) {
              $data = $ci-&gt;upload-&gt;data();
              $return[$data['file_name']] = 1;
          } else {
              $return[$image] = 0;
          }
      }
  
      return $return;
  }
  </code></pre>