title: Warning: end() expects parameter 1 to be array, string given on line 31
body: <p>I am pretty new to php, and trying to do a multiple images upload form( i am looping the process). For some reason i am having this warning(Warning: end() expects parameter 1 to be array, string given on line 31),Which is this line <code>($temp = ( $_FILES["file"]["name"][$i]);)</code></p>
  
  <p>please give me some help. Also, i am trying to make sure the image files are the right format and such before uploading them, so would i have to loop them once to make sure they are the correct format, then loop them again for the upload? 
  Ps. Ignore the SQL injection issue,will add those later. Thanks
  Php</p>
  
  <pre><code>&lt;?php
  ini_set('display_errors', 1); error_reporting(E_ALL);
  
  ob_start();
  session_start();
  include 'connect.php';
  
  
  
  if ($_POST)
  {
   //get form data
  
  
  
   $Listingname = addslashes(strip_tags($_POST['Listingname']));
   $Location = addslashes(strip_tags($_POST['Location']));
   $nobed = addslashes(strip_tags($_POST['nobed']));
   $zip = addslashes(strip_tags($_POST['zip']));
   $price = ($_POST['price']);
   $username=($_POST[$_SESSION['username']]);
  
   if (!$Listingname||!$nobed||!$nobed||!$zip||!$price)
      echo "Please fill out all fields"; 
      else 
  
      {$allowedExts = array("gif", "jpeg", "jpg", "png");
      $temp = $_FILES["file"]["name"];
      for($i=0;$i&lt;count($temp);$i++)
  $temp = ( $_FILES["file"]["name"][$i]);
  $extension = end($temp);
  if ((($_FILES["file"]["type"][$i] == "image/gif")
  || ($_FILES["file"]["type"][$i] == "image/jpeg")
  || ($_FILES["file"]["type"][$i] == "image/jpg")
  || ($_FILES["file"]["type"][$i] == "image/pjpeg")
  || ($_FILES["file"]["type"][$i] == "image/x-png")
  || ($_FILES["file"]["type"][$i] == "image/png"))
  &amp;&amp; ($_FILES["file"]["size"][$i] &lt; 400000)
  &amp;&amp; in_array($extension, $allowedExts))
    {
    if ($_FILES["file"]["error"][$i] &gt; 0)
      {
      echo "Return Code: " . $_FILES["file"]["error"][$i] . "&lt;br&gt;";
      }
    else
      {
      echo "Upload: " . $_FILES["file"]["name"][$i] . "&lt;br&gt;";
      echo "Type: " . $_FILES["file"]["type"][$i] . "&lt;br&gt;";
      echo "Size: " . ($_FILES["file"]["size"][$i] / 1024) . " kB&lt;br&gt;";
      echo "Temp file: " . $_FILES["file"]["tmp_name"][$i] . "&lt;br&gt;";
  
      if (file_exists("upload/" . $_FILES["file"]["name"][$i]))
        {
        echo $_FILES["file"]["name"][$i] . " already exists please add another file, or change the. ";
        }
      else
  
        {
          $photo=$_FILES["file"]["name"][$i];
        move_uploaded_file($_FILES["file"]["tmp_name"][$i],
        "upload/$photo");
        echo "Stored in: " . "upload/" . $_FILES["file"]["name"][$i];
        }
      }
    }
  
  else
  
  {
    echo "Invalid file" and die("Can not load picture");
    }
  
  
  
      {
         $username=$_SESSION['username'];
  
             //register into database
              mysqli_query($con,"INSERT INTO Listing (username,Listingname,Location,nobed,zip,price,pic1) VALUES 
                  ('$username','$Listingname','$Location','$nobed','$zip','$price','$photo');") or die(mysqli_error());
  
  
              echo "Listing Added";
  
      }
         }
  
      }
  
  
  
  else
  {
  
  ?&gt;
  
  &lt;form action="Submitlisting5.php" method="post"
  enctype="multipart/form-data"&gt;
  Listing Name:&lt;br /&gt;
  &lt;input type='text' name='Listingname'&gt;&lt;p /&gt;
  Location:&lt;br /&gt;
  &lt;input type='text' name='Location'&gt;&lt;p /&gt;
  Number of Beds:&lt;br /&gt;
  &lt;input type='test' name='nobed'&gt;&lt;p /&gt;
  Zip:&lt;br /&gt;
  &lt;input type='text' name='zip'&gt;&lt;p /&gt;
  Price:&lt;br /&gt;
  &lt;input type='text' name='price'&gt;&lt;p /&gt;
  
  
  &lt;label for="file"&gt;Pic1(File must be exceed 4mb):&lt;/label&gt;
  &lt;input type="file" name="file[]" id="file[]"&gt;&lt;br&gt;
  &lt;label for="file"&gt;Pic2(File must be exceed 4mb):&lt;/label&gt;
  &lt;input type="file" name="file[]" id="file[]"&gt;&lt;br&gt;
  &lt;br&gt;
  &lt;input type='submit' name='submit' value='Submit'&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>Just tried this, but now it goes straight to Can not upload picture</p>
  
  <pre><code> {$allowedExts = array("gif", "jpeg", "jpg", "png");
  
      for($i=0;$i&lt;4;$i++){
  $temp = ( $_FILES["file"]["name"]);
  $extension = $temp;
  if ((($_FILES["file"]["type"][$i] == "image/gif")
  || ($_FILES["file"]["type"][$i] == "image/jpeg")
  || ($_FILES["file"]["type"][$i] == "image/jpg")
  || ($_FILES["file"]["type"][$i] == "image/pjpeg")
  || ($_FILES["file"]["type"][$i] == "image/x-png")
  || ($_FILES["file"]["type"][$i] == "image/png"))
  &amp;&amp; ($_FILES["file"]["size"][$i] &lt; 400000)
  &amp;&amp; in_array($extension, $allowedExts))
  </code></pre>
  
  <p>Third Trial</p>
  
  <pre><code>for($i=0;$i&lt;4;$i++){
  
  
  if ((($_FILES["file"]["type"][$i] == "image/gif")
  || ($_FILES["file"]["type"][$i] == "image/jpeg")
  || ($_FILES["file"]["type"][$i] == "image/jpg")
  || ($_FILES["file"]["type"][$i] == "image/pjpeg")
  || ($_FILES["file"]["type"][$i] == "image/x-png")
  || ($_FILES["file"]["type"][$i] == "image/png"))
      &amp;&amp; ($_FILES["file"]["size"][$i] &lt; 400000))
  </code></pre>