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.

$pageURL = 'http';
$pageURL .= "://";
$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 />';

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.