In what ways can the navigation script be modified to exclude certain file types or extensions from being included, instead of using a blacklist approach?

To exclude certain file types or extensions from being included in the navigation script without using a blacklist approach, you can implement a whitelist approach by specifying the allowed file types or extensions to be included. This can be achieved by checking the file extension before adding it to the navigation menu.

$allowed_extensions = array('jpg', 'png', 'gif');

// Loop through files in directory
foreach(glob('*') as $file) {
    $file_extension = pathinfo($file, PATHINFO_EXTENSION);
    
    // Check if file extension is in the allowed list
    if(in_array($file_extension, $allowed_extensions)) {
        // Add file to navigation menu
        echo "<a href='$file'>$file</a><br>";
    }
}