What steps can be taken to troubleshoot and resolve the "File not found" error when using PHP scripts for file downloads?

The "File not found" error occurs when the PHP script is unable to locate the file specified for download. To troubleshoot and resolve this issue, ensure that the file path is correct, check file permissions, and verify that the file exists in the specified location.

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

if (file_exists($file_path)) {
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
    readfile($file_path);
    exit;
} else {
    echo 'File not found.';
}
?>