<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>PHP Index</title>
</head>
<body>
    <h2>Index of /</h2>

<?php
	
	$PREFIX = "https://vaucher.ca/assets/icons" ;
	
	// Using scandir()
//	echo "--------------------------------<br>\n";
//	echo "PHP index.php <br>";
//	echo "--------------------------------<p>";
	
	echo "URL: "  . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "<br>\n"  ;
	echo "--------------------------------<p>\n";

	$LINES = "";
	$files = scandir(".");
	foreach ($files as $file) 
	{
		if ($file[0] == "." && $file <> "..") continue;
		
		$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
			
		if(is_dir($file))		
			$Icon = "folder.gif";
		else if (in_array($ext, ['gif', 'jpeg', 'jpg', 'heic', 'png'])) 
			$Icon = "image.gif";				
		else if (in_array($ext, ['zip', 'gz'])) 
			$Icon = "compressed.gif";		
		else  if ($ext == 'tar')	
			$Icon = "tar.gif";		
		else 
			$Icon = "text.gif";
			
	$LINES .= <<<EOD
	  <tr>
		<td valign="top">
			<img src="$PREFIX/$Icon" >
		</td>
             <td>
                <a href="$file">$file</a>
            </td>
            <td>&nbsp;</td>
        </tr>
	  </tr>

EOD;
	}
	
echo <<<EOD
	<div style="margin-left: 50px">	
      <table>

		$LINES	

	  </table>
	</div> 
EOD;

?>


</body>
</html>
