Show content of folder in PHP

To show the content of a directory in PHP and make the files like images etc downloadable without changing the Webserver config, upload this snippet as index.php to the directory.

<?php
$pageURL = 'http';
$pageURL .= "://";
$pageURL .= $_SERVER["SERVER_NAME"];
$httpfolder = $pageURL.$_SERVER["REQUEST_URI"]; // The link to this folder from outside, with slash at end
$dir = getcwd();
$files = array_diff(scandir($dir), array('..', '.','index.php'));

foreach($files as $file) {
    echo '<a href="'.$httpfolder.$file.'">'.$file.'</a><br />';
}
?>