title: Add more images to the front page (index.php) banner and grab dynamically
body: <p>okay, so very very new to PHP, and trying to complete my first major assignment.  I'm nearly finish however very stuck, and tutor/school have not been the most helpfull. I need to know how to solve this, in the easiest term so that i understand this for later. Thanks in advance.</p>
  
  <p>question 2. 
  so i have to Add more images to the front page (index.php) banner and make it rotate through the images. Store the images in the "Images/banner" folder and dynamically grab them. </p>
  
  <p>how i have been able to create a javascript code to create the anner rotation, i just can't work out the php to dynamically grab them. </p>
  
  <p>below is the banner page that allows upload of banner to image.banner folder. </p>
  
  <p>i also have another question relating to same file which is </p>
  
  <p>question 2
   There is a bug on the "editBanner.php" page. When you delete an image, that number is deleted. When a new file is uploaded, it is given the number of one more than the total of current banners. There is a major problem with this, e.g. if we have four banners: 1.jpg, 2.jpg, 3.jpg and 4.jpg. If we delete 2.jpg, we are left with 1.jpg, 3.jpg and 4.jpg. If we then uploaded a new image, the page would count the number of images (in this case three) and add 1, giving us a new file name of "4.jpg". We already have a file called 4.jpg, therefore, the old 4.jpg would be replaced. Find a way to fix this error so the images are never replaced</p>
  
  <pre><code>&lt;?php
  require_once("Includes/simplecms-config.php");
  require_once("Includes/connectDB.php");
  include("Includes/header.php");
  
  confirm_is_admin();
  
  $dir = 'Images/banner';
  $confirmation = "";
  
  if (isset($_GET["del"])) {
      if (file_exists($dir . "/" . $_GET["del"])) {
          unlink($dir . "/" . $_GET["del"]);
          $confirmation = $_GET["del"] . " deleted. &lt;br&gt;&lt;br&gt;";
      } else {
          $confirmation = $_GET["del"] . " doesn't exist. &lt;br&gt;&lt;br&gt;";
      }
  }
  
  $files = scandir($dir);
  array_shift($files);
  array_shift($files);
  
  $newImage = COUNT($files) + 1;
  
  if (isset($_GET["add"])) {
      $confirmation = "Image successfully uploaded.";
  }
  
  if (isset($_FILES["file"]["name"])) {
      $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; 50 * 1024 * 1024) //50mb (1024 * 1kb = 1mb, 50 x 1024kb = 50mb)
          &amp;&amp; in_array($extension, $allowedExts)
      ) {
          if ($_FILES["file"]["error"] &gt; 0) {
              echo "Return Code: " . $_FILES["file"]["error"] . "&lt;br&gt;";
          } else {
              echo "Upload: " . $_FILES["file"]["name"] . "&lt;br&gt;";
              echo "Type: " . $_FILES["file"]["type"] . "&lt;br&gt;";
              echo "Size: " . ($_FILES["file"]["size"] / 1024) . " 
             kB&lt;br&gt;";
              echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
            &lt;br&gt;";
              move_uploaded_file($_FILES["file"]["tmp_name"], $dir .
                  "/" . $newImage . "." . $extension);
              echo "Stored in: " . $dir . "/" . $_FILES["file"]
                  ["name"];
              header("Location: editBanner.php?add=1");
          }
      } else {
          echo "Invalid file";
      }
  }
  ?&gt;
      &lt;div id="container"&gt;
          &lt;div id="admin"&gt;
              &lt;?php
              if (!empty($confirmation)) {
                  echo "&lt;div id='confirmation'&gt;" . $confirmation . "&lt;/div&gt;";
              }
  
              for ($i = 0; $i &lt; COUNT($files); $i++) {
                  echo '&lt;div id="bannerImage"&gt;';
                  echo $files[$i] . ' - &lt;a href="editBanner.php?del=' .
                      $files[$i] . '"&gt;Delete&lt;/a&gt;&lt;br&gt;';
                  echo '&lt;img src="' . $dir . '/' . $files[$i] . '"width="200px" height="100px" /&gt;&lt;br&gt;';
                  echo '&lt;/div&gt;';
                  $files[$i--];
              }
              ?&gt;
  
              &lt;style&gt;
                  #bannerAdd {
                      float: right;
                      margin-right: 700px;
                  }
              &lt;/style&gt;
              &lt;div id="bannerAdd"&gt;
                  &lt;form action="editBanner.php" method="post"
                        enctype="multipart/form-  data"&gt;
                      &lt;h3&gt;Upload a New Banner Image&lt;/h3&gt;
                      &lt;input type="file" name="file" id="file"&gt;&lt;br&gt;
                      &lt;input type="submit" name="submit" value="Submit"&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt; &lt;!-- End of outer-wrapper which opens in header.php --&gt;
  
  &lt;?php
  include("Includes/footer.php");
  ?&gt;
  </code></pre>