
<html><head></head><body>
<?php

/*
To pass an image to file download_image.php, append a question mark to download_image.php 
followed by the name of the input in download_image.php to which the name of the file will 
be assigned which is called f in that file (This is the same as having an input field with name f, 
but here we get the value of this field f from the URL or the link not from a form. That's 
why you need here to use GET or REQUEST but not POST.) followed by equal sign followed by the 
name of the image to download (you can't include it in quotes). If there is another input you need 
to assign a valeu to, you write & followed by the name of that input followed by = followed by the 
value of that input.
When ypu use this procedure, you should be very careful because you don't want people to be able 
to download any file in any directory.
*/

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

  $valid_type = array("gif","jpg","jpeg","png","bmp");
  $dir = opendir($d) or exit("Can't open the directory");
  while ($file_name = readdir($dir))
  {
        $file = $d.$file_name;
        $wanted = false;
        if (is_readable($file))
        {
                // Reverse the file name to get the extension
                $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))
			// Attach the name of the image to the URL
                        echo "<a href=\"download_image.php?f=$file_name\">$file_name</a><br>\n";
        }
}
@closedir($dir);
?>

</body>
</html>

