How can PHP scripts be modified to check for the existence of an image file before generating and displaying it in an HTML page?

To check for the existence of an image file before generating and displaying it in an HTML page, you can use the PHP function `file_exists()` to verify if the image file exists in the specified directory. If the file exists, you can then proceed to generate and display the image in the HTML page. If the file does not exist, you can display a default image or a placeholder instead.

<?php
$imagePath = 'path/to/image.jpg';

if(file_exists($imagePath)) {
    echo '<img src="' . $imagePath . '" alt="Image">';
} else {
    echo '<img src="path/to/default-image.jpg" alt="Default Image">';
}
?>