Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/

comments.php
exercises/
exercises.php
img/
incl/
index-no-include.php
index.php
laragon/
source.php
style/
viewsource.php

exercises.php

54 lines ASCII Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Exercises Folder</title>
</head>
<body>
  <h1>Exercises</h1>
  <ul>
    <?php
      $parentDir 
'exercises';

      
      function 
listFilesInDir($dir) {
         
          if (
$handle opendir($dir)) {
      
              echo 
"<ul>";
      
              
              while (
false !== ($file readdir($handle))) {
      
                 
                  if (
$file != "." && $file != "..") {
      
                     
                      if (
is_dir("$dir/$file")) {
                          
                          echo 
"<li><strong>$file</strong> (Directory)";
                          
listFilesInDir("$dir/$file");
                          echo 
"</li>";
                      } else {
                         
                          echo 
"<li><a href='$dir/$file'>$file</a></li>";
                      }
                  }
              }
      
              echo 
"</ul>";
      
              
              
closedir($handle);
          } else {
              echo 
"Unable to open directory: $dir";
          }
      }
      
      
      
listFilesInDir($parentDir);
    
?>
  </ul>
</body>
</html>