How can PHP be used to check if a specific file exists before displaying it?

To check if a specific file exists before displaying it in PHP, you can use the `file_exists()` function. This function takes the file path as an argument and returns `true` if the file exists and `false` if it does not. By using this function, you can ensure that you only attempt to display files that actually exist on the server.

$file_path = 'path/to/file.txt';

if (file_exists($file_path)) {
    // Display the file content
    echo file_get_contents($file_path);
} else {
    echo 'File does not exist.';
}