Hello, I wrote a simple script to display all the files/folders in a directory. When you click a file it will open the file. When you click a directory it SHOULD list all the files/folders in that directory.

Here is my script:
PHP Code:
<?php
$html
="";
$dir='.';
if(isset(
$_GET['dir'])){
if(
strlen($_GET['dir']) > 0){
$dir $_GET['dir'];
}
}
if (
$handle opendir($dir)) {
    
$html .= "<table style='border: 1px solid black;'>";
    while (
false !== ($file readdir($handle))) {
        if (
$file != "." && $file != "..") {
        if(!
is_dir($file)){
         
$html .= "<tr><td><a href='".$dir.'/'.$file."'>$file</a></td></tr>";
        }
        else{
        
$html .= "<tr><td><a href='index.php?dir=".$dir.'/'.$file."'>$file</a></td></tr>";
        }
    }
    }
    
$html .= "</table>";
    
closedir($handle);
}
echo 
$html;
?>
Don't just correct the code, please provide an explanation so I don't repeat this error in the future.