Current course:

Display all the images from a folder


function getFiles($dir) {
      //sets a array to hold the files
      $dir_array = array();

      //attempts to open the directory
      if($handle = opendir($dir)) {

            //repeats through each file in the folder
            while(false !== ($file = readdir($handle))) {

                  //if it doesn't match any junk files, add it to the array
                  if($file != "." && $file != ".." && $file != ".DS_Store") {
                        array_push($dir_array, $file);
                  }
            }
            //closes the directory
            closedir($handle);
      }

      //returns the array of files
      return $dir_array;
}


//calls the function that retrieves the files from the images folder
$images = getFiles('images/');


//checks if there were any files found
if(sizeof($images) > 0) {

      //repeats through and writes each image to the page
      foreach($images as $img) {
            echo "<img src='images/" . $img . "' /><br />";
      }

//if no files found, let the user know
} else {
      echo "No images found.";
}