What are some alternatives to displaying hyperlinks in PHP-generated HTML code to prevent exposing complete file paths and filenames?

When displaying hyperlinks in PHP-generated HTML code, it is important to prevent exposing complete file paths and filenames to enhance security. One way to achieve this is by using a function like basename() to extract just the filename from the path before displaying it as a hyperlink. This ensures that only the filename is visible to the users, while the actual file path remains hidden.

<?php
$file_path = '/path/to/file/filename.txt';
$file_name = basename($file_path);
echo '<a href="' . $file_path . '">' . $file_name . '</a>';
?>