What is the purpose of the remoteFileExists function in the PHP script?

The purpose of the remoteFileExists function in the PHP script is to check if a file exists on a remote server by sending a HEAD request to the file URL. This function can be useful when you need to verify the existence of a file before performing operations on it, such as downloading or processing it.

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

// Example usage
$fileUrl = "http://example.com/file.txt";
if(remoteFileExists($fileUrl)){
    echo "File exists!";
} else {
    echo "File does not exist!";
}