Connecting files

Please tell me how this functionality can be organized?
It is necessary that the page is displayed on the page with files from the directory and when the user is selected, the selected file was connected!


Answer 1, Authority 100%

something like that.

<?php
$fdir = './';
if(! is_dir($fdir))
    exit('  .');
if(!empty($_GET['file'])){
    $file = trim($_GET['file']);
    $file = basename($file);
    $f    = end(explode('/', $file));       
    if (substr($file, 0, 1) == '.'){
        print '   .';    
    }elseif(file_exists($file) && is_readable($file)){
        //     ,   require/include,      .     .
        print htmlspecialchars(file_get_contents($file)); //
        //  include($file);
    }else{
        print '  .';
    }
    print "<br />";     
}
$dir = opendir($fdir);
while($file = readdir($dir)){
    if( is_file($file) && substr($file, 0, 1) != '.' ) //     .htpasswd, .htaccess,  ..
        print "<a href='?file={$fdir}{$file}'>$file</a><br />"; 
}
?>