title: File disappears after multi-file upload in Codeigniter
body: <p>I've made an upload form for an admin page within Codeigniter that uploads a new HTML form and relevant PHP files into a database for users to access</p>
  
  <p>I can select several files to upload but one of my files will not upload and I can't understand why - even if I try to upload it individually. Below I've included the HTML upload form, the codeigniter controller and the contents of the file that won't upload. All the other files will upload. </p>
  
  <p><strong>The Upload Form</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="row"&gt;
    &lt;div class="col-sm-12"&gt;
      &lt;div class="white-box"&gt;
        &lt;h3 class="box-title m-b-0"&gt;Resource Upload Form&lt;/h3&gt;
        &lt;p class="text-muted m-b-30 font-13"&gt; Upload your resource to the live database &lt;/p&gt;
  
        &lt;form class="form-horizontal" id="uploadForm" action="&lt;?php echo base_url();?&gt;resources/do_uploads" method="post" name="form" enctype="multipart/form-data"&gt;
          &lt;fieldset&gt;
  
            &lt;!-- Form Name --&gt;
            &lt;legend&gt;Upload Resource&lt;/legend&gt;
  
            &lt;!-- Text input--&gt;
            &lt;div class="form-group"&gt;
              &lt;label class="col-md-4 control-label" for="resource_name"&gt;Resource Name&lt;/label&gt;
              &lt;div class="col-md-5"&gt;
                &lt;input id="resource_name" name="resource_name" type="text" placeholder="" class="form-control input-md" required&gt;
                &lt;span class="help-block"&gt;Name of the resource that is being uploaded&lt;/span&gt;
              &lt;/div&gt;
            &lt;/div&gt;
  
            &lt;!-- Textarea --&gt;
            &lt;div class="form-group"&gt;
              &lt;label class="col-md-4 control-label" for="resource_description"&gt;Resource Description&lt;/label&gt;
              &lt;div class="col-md-4"&gt;
                &lt;textarea class="form-control" id="resource_description" name="resource_description"&gt;&lt;/textarea&gt;
              &lt;/div&gt;
            &lt;/div&gt;
  
            &lt;!-- File Button --&gt;
            &lt;!-- Form --&gt;
  
            &lt;!-- Multiple Checkboxes (inline) --&gt;
            &lt;div class="form-group"&gt;
              &lt;label class="col-md-4 control-label" for="year_group"&gt;Year Group&lt;/label&gt;
              &lt;div class="col-md-4"&gt;
                &lt;label class="checkbox-inline" for="year_group-0"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-0" value="1"&gt; 1
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-1"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-1" value="2"&gt; 2
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-2"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-2" value="3"&gt; 3
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-3"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-3" value="4"&gt; 4
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-4"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-4" value="5"&gt; 5
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-5"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-5" value="6"&gt; 6
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-6"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-6" value="eyfs"&gt; EYFS
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-7"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-7" value="ks1"&gt; KS1
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-8"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-8" value="ks2"&gt; KS2
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-9"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-9" value="lks2"&gt; LKS2
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-10"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-10" value="uks2"&gt; UKS2
                              &lt;/label&gt;
                &lt;label class="checkbox-inline" for="year_group-11"&gt;
                                  &lt;input type="checkbox" name="year_group" id="year_group-11" value="all"&gt; All
                              &lt;/label&gt;
              &lt;/div&gt;
            &lt;/div&gt;
  
            &lt;!-- Multiple Radios (inline) --&gt;
            &lt;div class="form-group"&gt;
              &lt;label class="col-md-4 control-label" for="subscriber_level"&gt;Subscriber Level&lt;/label&gt;
              &lt;div class="col-md-4"&gt;
                &lt;label class="radio-inline" for="subscriber_level-0"&gt;
                                  &lt;input type="radio" name="subscriber_level" id="subscriber_level-0" value="free" checked="checked"&gt; Free
                              &lt;/label&gt;
                &lt;label class="radio-inline" for="subscriber_level-1"&gt;
                                  &lt;input type="radio" name="subscriber_level" id="subscriber_level-1" value="basic"&gt; Basic
                              &lt;/label&gt;
                &lt;label class="radio-inline" for="subscriber_level-2"&gt;
                                  &lt;input type="radio" name="subscriber_level" id="subscriber_level-2" value="premium"&gt; Premium
                              &lt;/label&gt;
              &lt;/div&gt;
            &lt;/div&gt;
  
            &lt;div class="form-group"&gt;
              &lt;label class="col-md-4 control-label" for="resource_name"&gt;Resource Name&lt;/label&gt;
              &lt;div class="col-md-5"&gt;
                &lt;input type="file" name="userfiles[]" size="20" multiple /&gt;
              &lt;/div&gt;
            &lt;/div&gt;
  
            &lt;!-- Button --&gt;
            &lt;div class="form-group"&gt;
              &lt;label class="col-md-4 control-label" for="submit"&gt;Submit&lt;/label&gt;
              &lt;div class="col-md-4"&gt;
                &lt;button id="submit" name="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
              &lt;/div&gt;
            &lt;/div&gt;
  
          &lt;/fieldset&gt;
          &lt;br /&gt;
          &lt;br /&gt;
        &lt;/form&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>The Upload Controller</strong>
  </p>
  
  <pre><code>function do_uploads($page = "")
      {
          $createDirName = uniqid();
          $dirName = 'application/views/resources/' . $createDirName;
          mkdir($dirName);
          $config['upload_path'] = $dirName;
          $config['allowed_types'] = 'gif|jpg|png|bmp|php';
          //$config['max_size'] = '1024';
          //$config['encrypt_name'] = TRUE;
          $config['remove_spaces'] = TRUE;
  
          $this-&gt;load-&gt;library('upload', $config);
          $this-&gt;upload-&gt;initialize($config);
  
          var_dump($_FILES['userfiles']);
  
          $fileInfos = array();
          $errors = array();
          if (! empty($_FILES['userfiles']['name'])) {
              $photosCount = count($_FILES['userfiles']['name']);
              for ($i = 0; $i &lt; $photosCount; $i ++) {
                  // Create file upload info
                  $_FILES['userfile']['name'] = $_FILES['userfiles']['name'][$i];
                  $_FILES['userfile']['type'] = $_FILES['userfiles']['type'][$i];
                  $_FILES['userfile']['tmp_name'] = $_FILES['userfiles']['tmp_name'][$i];
                  $_FILES['userfile']['error'] = $_FILES['userfiles']['error'][$i];
                  $_FILES['userfile']['size'] = $_FILES['userfiles']['size'][$i];
                  $data['fileName'] = $_FILES['userfiles']['name'][$i];
                  //$mode = 0777;
                  //chmod(base_url() . $dirName, octdec($mode));
                  // Upload file to server
                  if ($this-&gt;upload-&gt;do_upload('userfile')) {
                      array_push($fileInfos, array(
                          'userfile' =&gt; $this-&gt;upload-&gt;data()
                      ));
                  } else {
                      array_push($errors, array(
                          'error' =&gt; $this-&gt;upload-&gt;display_errors(),
                          'count' =&gt; $photosCount,
                      ));
                  }
              }
          }
      }
  </code></pre>
  
  <p><strong>The Contents of the file that won't Upload with the above: index.php</strong>
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form class="needs-validation" id="questionsform" action="&lt;?php echo base_url();?&gt;resources/loadSheet/additionWorksheets/generator" method="post" name="form"&gt;
    Choose the maximum number of digits for the top number.&lt;br /&gt;
    &lt;table style="width:100%"&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;input type="radio" name="topNumber" value="1"&gt; 1&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="topNumber" value="2"&gt; 2&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="topNumber" value="3"&gt; 3&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="topNumber" value="4"&gt; 4&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="topNumber" value="5"&gt; 5&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="topNumber" value="6"&gt; 6&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="topNumber" value="7"&gt; 7&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  
    Choose the maximum number of digits for the bottom number. &lt;br /&gt;
    &lt;table style="width:100%"&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;input type="radio" name="bottomNumber" value="1"&gt; 1&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="bottomNumber" value="2"&gt; 2&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="bottomNumber" value="3"&gt; 3&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="bottomNumber" value="4"&gt; 4&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="bottomNumber" value="5"&gt; 5&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="bottomNumber" value="6"&gt; 6&lt;/td&gt;
        &lt;td&gt;&lt;input type="radio" name="bottomNumber" value="7"&gt; 7&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  
    &lt;input id="toHide" type="radio" name="calculation" value="addition" checked="checked"&gt;&lt;br&gt;
  
    &lt;br/&gt;
    &lt;button type="submit"&gt;Submit&lt;/button&gt;
    &lt;/div&gt;
    &lt;br/&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>