What are the potential challenges of displaying a PDF file located outside the htdocs directory in a browser using PHP?

When displaying a PDF file located outside the htdocs directory in a browser using PHP, one potential challenge is that the file path may not be accessible due to security restrictions. To solve this issue, you can use PHP to read the file content and then output it to the browser using appropriate headers.

<?php
$file_path = '/path/to/external/file.pdf';

if (file_exists($file_path)) {
    header('Content-Type: application/pdf');
    header('Content-Disposition: inline; filename="file.pdf"');
    readfile($file_path);
} else {
    echo 'File not found.';
}
?>