What are the limitations of accessing local files using HTML in PHP scripts?

Accessing local files using HTML in PHP scripts can be a security risk as it exposes sensitive information on the server. To prevent this, it is recommended to use PHP functions like file_get_contents() or fopen() to read files instead of directly linking them in HTML.

$file_path = "path/to/file.txt";
$file_contents = file_get_contents($file_path);
echo $file_contents;