$url = 'http://some.url/file.txt';
$data = download($url, $headers, $err_msg);
if( !$data ) {
echo $err_msg;
die;
}
print_r($headers);
echo stream_get_contents($data);
This is conceptually similar to:
echo stream_get_contents(fopen($url, 'r'))
The differences are:
- We can get better error info.
- We can get the HTTP headers so we know things like the content type.
- Since we are using the curl library it works even when fopen doesn't allow URLs.