title: Upload multiple images on server
body: <p>i was trying to code a form that helps in uploading images, after a little research over this site i had this script, however it is uploading only single image whereas i wish to upload multiple images on server folder and store their path in database table </p>
  
  <pre><code>&lt;form action="insertimages.php" method="post" enctype="multipart/form-data"&gt;
  &lt;div class="form-group"&gt;
  &lt;label class="col-md-3 control-label"&gt;Upload Image:&lt;/label&gt;
  &lt;div class="col-md-8"&gt;
  &lt;input class="form-control" name="file" id="file" value="" type="file" multiple required&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
  &lt;label class="col-md-3 control-label"&gt;&lt;/label&gt;
  &lt;div class="submit"&gt;
  &lt;input class="btn btn-primary" value="Save " type="submit" name="submit"&gt;
  &lt;/div&gt;  
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Code of insertimages.php page is</p>
  
  <pre><code>$con=mysqli_connect("localhost","root","","db");
  // Check connection
  if (mysqli_connect_errno()) 
      {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
  $allowedExts = array("gif", "jpeg", "jpg", "png");
  $temp = explode(".", $_FILES["file"]["name"]);
  $extension = end($temp);
  
  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; 2000000)
  &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("images/" . $_FILES["file"]["name"])) 
                      {
                          echo $_FILES["file"]["name"] . " already exists. ";
                      } 
                  else 
                      {
  
                          $imagepath = "images/" . $_FILES["file"]["name"];
                          move_uploaded_file($_FILES["file"]["tmp_name"], $imagepath);
                          $sql="INSERT INTO images(image,studentid) VALUES ('".$imagepath."','".$_SESSION['insert_id']."')";
                          if (!mysqli_query($con,$sql)) 
                              {
                                  die('Error: ' . mysqli_error($con));
                              }
                      }
              }
              header("Location: index.php");
      } 
  else    
      {
          echo "Invalid file";
      }
  
  ?&gt;
  </code></pre>
  
  <p>can anyone rectify the error and help me </p>