<?php 
  function getDirectoryList ($directory) 
  {
    // create an array to hold directory list
    $results = array();

    // create a handler for the directory
    $handler = opendir($directory);

    // open directory and walk through the filenames
    while ($file = readdir($handler)) {

      // if file isn't this directory or its parent, add it to the results
      //if ($file != "." && $file != "..") {
        $results[] = $file;
      //}

    }

    // tidy up: close the handler
    closedir($handler);

    // done!
    natsort($results);
    return $results;

  }
?>
<!doctype html>
<html>
<head>
  <title>Murach's PHP &amp; MySQL</title>
</head>
<body>
  <h1>Murach's PHP &amp; MySQL</h1><?php
$imagepath = "http://bscacad3.buffalostate.edu/~gerlanjr/images/";
$d = getDirectoryList("./");

// while (list($key,$val) = each($d)) {
foreach ($d as $key => $val) {
  $image = "Unknown-icon.png";
  // echo(' val=' . $val . '<br/>');
  if (($val != "index.php") && ($val != "download.php")) {
    if (preg_match("/.css/i",$val))   { $image = "css-icon.png"; }
    if (preg_match("/\.doc/i",$val))  { $image = "Word-icon.png"; }
    if (preg_match("/\.gif/i",$val))  { $image = "gif-icon.png"; }
    if (preg_match("/\.htm/i",$val))  { $image = "html-icon.png"; }
    if (preg_match("/\.ico/i",$val))  { $image = "ICO-icon.png"; }
    if (preg_match("/\.java/i",$val)) { $image = "java-icon.png"; }
    if (preg_match("/\.js/i",$val))   { $image = "JavaScript-icon.png"; }
    if (preg_match('/\.php/i',$val))  { $image = "php-icon.png"; }
    if (preg_match('/\.png/i',$val))  { $image = "png-icon.png"; }
    if (preg_match("/\.ppt/i",$val))  { $image = "PowerPoint-icon.png"; }
    if (preg_match("/\.txt/i",$val))  { $image = "txt-icon.png"; }
    if (preg_match("/\.xls/i",$val) || preg_match("/\.csv/i",$val)) { $image = "Excel-icon.png"; }
    if (is_dir($val)) { $image = "Folder-icon.png"; }
    if ($val == ".") { $image = "Folder-icon.png"; }
    $valHref = $val; // str_replace(" ", "%20", $val);
    echo("<img src=\"$imagepath$image\"/> <a href=\"$valHref\">$val</a>");
    if (!is_dir($val)) { echo(" (<a href=\"download.php?file=$val\">download</a>)"); }
    $filemod = filemtime($val);
    $filemodtime = date("F j Y h:i:s A", $filemod); 
    echo(" $filemodtime<br>\n");
  }
}
?>
</body>
</html> 