title: How to upload an array of files?
body: <p>I'm trying to build an array of files by submitting a form several times, then move those files to a directory, but it's not working. Every uploads just overrides the previous and then it doesn't even move that one (the upload_to_file() function doesn't do anything)</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form id="form" action="home.php" method="post" enctype="multipart/form-data"&gt;
          &lt;input type="hidden" name="MAX_FILE_SIZE" value="8000000"&gt;
          &lt;input class="upload_btn" type="file" name="images[]" id="image_file"&gt;
          &lt;input type="submit" id="img_submit" class="form_button" name="submit_image" value="upload"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>It is important that there is only one upload button which can be used to upload many files. </p>
  
  <p>I need them to be stored in an array so I can display their ['name'] anywhere with a loop.<code>for ($i = 0; $i &lt; count($_FILES['images']['name']); $i++){}</code></p>
  
  <p>Then once another form is submitted it calls a function to move each file in the array to a directory.</p>
  
  <p>Function inside an included php file:</p>
  
  <pre><code>function upload_to_file(){
  $image_paths = array();
  $target_dir = "uploads/images/";
  $path = $target_dir . basename($_FILES['images']['name'][0]);
  
  if(isset($_FILES['images']['name'][0]) &amp;&amp; $_FILES['images']['size'][0] &gt; 0)
  {
      if (move_uploaded_file($_FILES['images']['tmp_name'][0], $path)) {
          $image_paths[0] = "uploads/images/";
      }
  }
  return $image_paths;
  
  }
  </code></pre>
  
  <p>I'm only testing it with the first element in the array, but will need to make a loop later.</p>