<html><head></head><body>
<!-- Solution of Quiz 2 - CSIT 207 - Spring 2007 -->
<?php

  $d = "/home/abu-jeib/temp2/";

  $valid_type = array("gif","jpg","jpeg","png","bmp");
  $valid_type2 = array(".gif",".jpg",".jpeg",".png",".bmp");
  $dir = opendir($d) or exit("Can't open the directory");
  $count = 0;
  while ($file_name = readdir($dir))
  {
	$x = strrev($file_name);
	$y = split("\.",$x);
	$ext = strrev($y[0]);
	$lowercase_ext = strtolower($ext);
	// Check if the extension is wanted
	if (in_array($lowercase_ext,$valid_type))
		$count++;
	/*
			 $ext = strtolower(substr($file_name,-4,4));
                        if (in_array($ext,$valid_type2))
                                $count++;
                        else
                        {
                                $ext = strtolower(substr($file_name,-5,5));
                                if (in_array($ext,$valid_type2))
                                        $count++;
                        }

	*/

 }
 @closedir($dir);
 echo "There are $count files in the $d directory";
 
?>

</body>
</html>
