title: Uploading multiple files using html5 and php
body: <p>I have a file upload form set up with the HTML5 multiple attribute. </p>
  
  <p>However, the form still only uploads a single file. Do i need to create some sort of a looping function in the php or is there another way of doing this?</p>
  
  <p>Here's my code...</p>
  
  <p>form:</p>
  
  <pre><code>&lt;form action="&lt;?php $_SERVER['PHP_SELF'] ?&gt;" method="post" enctype="multipart/form-data"&gt;        
         &lt;input type="file" multiple="multiple" name="file[]" id="file" /&gt;
         &lt;input name="submit" type="submit" value="Submit" /&gt;    
  &lt;/form&gt;
  </code></pre>
  
  <p>php:</p>
  
  <pre><code>&lt;?php
  if(isset($_POST['submit'])) {           
  foreach($_FILES['newsImage'] as $file){ 
  if ((($_FILES["file"]["type"] == "image/jpeg")
  || ($_FILES["file"]["type"] == "image/pjpeg")))
    {
    if ($_FILES["file"]["error"] &gt; 0)
      {
      echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br /&gt;";
      }
    else
      {
  
  
      if (file_exists("upload/" . $_FILES["file"]["name"]))
        {
        echo $_FILES["file"]["name"] . " already exists. ";
        }
      else
        {
        move_uploaded_file($_FILES["file"]["tmp_name"],
        "upload/" . $_FILES["file"]["name"]);
        echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
        }
      }
    }
  else
    {
    echo "Invalid file";
    }
  }
  }
  ?&gt;
  </code></pre>