How can the file_exists() function in PHP be used to check for the existence of a remote file?

When using the file_exists() function in PHP, it can only be used to check for the existence of local files on the server where the script is running. To check for the existence of a remote file, you can use other methods such as cURL to make a request to the remote file and check the response status.

function remote_file_exists($url){
    $headers = get_headers($url);
    return strpos($headers[0], '200') !== false;
}

$url = 'http://www.example.com/remote_file.txt';
if(remote_file_exists($url)){
    echo "Remote file exists!";
} else {
    echo "Remote file does not exist.";
}