How can error handling be implemented in PHP to display a default image if the specified image file is not found?

When displaying images in PHP, it is important to handle errors that may occur if the specified image file is not found. One way to implement error handling is to check if the file exists using the file_exists() function before attempting to display it. If the file does not exist, a default image can be displayed instead.

$image_path = "path/to/your/image.jpg";

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