What are some best practices for handling file existence checks on external resources in PHP?

When working with external resources in PHP, it is important to check if the file exists before attempting to access or manipulate it. This helps prevent errors and ensures that your code behaves as expected. One common way to handle file existence checks is by using the `file_exists()` function in PHP.

// Check if a file exists before accessing it
$filePath = 'https://www.example.com/image.jpg';

if (file_exists($filePath)) {
    // File exists, perform actions here
    echo 'File exists!';
} else {
    // File does not exist, handle error or take appropriate action
    echo 'File does not exist.';
}