title: Uploading multiple files in server
body: <p>I want to upload multiple files instead of just one. I know how to upload a single file (image) I need help with uploading multiple files. Below you can see how I do to upload a single file.</p>
  
  <p>Here is my HTML when adding:</p>
  
  <pre><code>    &lt;form action="upload_file.php" method="post" enctype="multipart/form-data"&gt;
      &lt;label for="file"&gt;Filename:&lt;/label&gt;
      &lt;input type="file" name="file" id="file" multiple&gt;&lt;br&gt;
      &lt;input type="submit" name="submit" value="Submit"&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>I have seen some people change <strong>name="file"</strong> to <strong>name="file[]"</strong>. But I don't know how to upload it with php.</p>
  
  <p>Here is the PHP code</p>
  
  <pre><code>   &lt;?php
      $allowedExts = array("gif", "jpeg", "jpg", "png");
      $temp = explode(".", $_FILES["file"]["name"]);
      $extension = end($temp);
  
      $random_digit=rand(0000,9999);
  
      if ((($_FILES["file"]["type"] == "image/gif")
      || ($_FILES["file"]["type"] == "image/jpeg")
      || ($_FILES["file"]["type"] == "image/jpg")
      || ($_FILES["file"]["type"] == "image/pjpeg")
      || ($_FILES["file"]["type"] == "image/x-png")
      || ($_FILES["file"]["type"] == "image/png"))
      &amp;&amp; ($_FILES["file"]["size"] &lt; 20000)
      &amp;&amp; in_array($extension, $allowedExts))
      {
      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
    {
    $file_name = $_FILES["file"]["name"];
    $ext = pathinfo($file_name, PATHINFO_EXTENSION); // Get the extension of a file
    $new_file_name = $random_digit . '.' . $ext;
    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $new_file_name);
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
       }
     }
   }
  else
   {
   echo "Invalid file";
   }
   ?&gt; 
  </code></pre>