How can PHP be used to automate the process of creating an index page for a directory?

When dealing with a directory containing multiple files, manually creating an index page can be time-consuming and prone to errors. To automate this process, we can use PHP to dynamically generate an index page that lists all the files in the directory with clickable links for easy navigation.

<?php
$dir = "./your_directory_path_here/";
$files = scandir($dir);

echo "<h1>Index of Files</h1>";
echo "<ul>";
foreach($files as $file) {
    if($file != "." && $file != "..") {
        echo "<li><a href=\"$dir$file\">$file</a></li>";
    }
}
echo "</ul>";
?>