<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
<title>Show files in directory and allow opening</title> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" /> 
<meta name="description" content="Show files in directory" /> 
</head> 
<body> 

<?php 
// function to get file names 
function scandir($dirstr) 
{   // php.net/scandir (PHP5) 
    $files = array(); 
    $fh = opendir($dirstr); 
    while (false !== ($filename = readdir($fh))) 
    { 
        array_push($files, $filename); 
    } 
    closedir($fh); 
    sort($files); 
    return $files; 
} 

$cwd = getcwd(); 
echo "<p> Contents of Directory: $cwd </p>"; 

$scanlist = scandir("$cwd"); 

foreach ($scanlist as $filename) 
{ 
    echo "<a href=\"$filename\">$filename</a> <br/>"; 
} 
?> 

</body> 
</html> 
