Doesn’t work! What’s the problem?

This script receives files from the directory, and then displays a link to the file, and if the user clicks on the link, the script displays the contents of the file or it can be connected to the script, because. you need it.

<?php
$fdir = 'grabbed_old';
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 />"; 
}
?>

Answer 1, authority 100%

Problem in script logic

if (empty($_GET['FileName'])) {
    //  
}
else{
    //  
}