Possible Duplicate:
file_get_content failed to open stream: Connection refused
file_get_conte开发者_高级运维nt function was not working on Linux vqs332.pair.com 2.6.32-33-server. Either i need to change any setting in my php.ini or some other problem. I'm using this function to get latitude and longitude from the address (dynamic).
file_get_contents("http://maps.google.com/maps/api/geocode/json?address=24411+Health+Center+Dr+Suite+200&sensor=false");
Plz guide me.
The problem is probably that your host has allow_url_fopen
disabled. This is quite common in shared hosting environments and is a sensible security precaution.
In order to get around the problem you will have to download the file with cURL to a local path and use it locally.
e.g.
// Remote file we want, and the local file name to use as a temp file
$url = 'http://maps.google.com/maps/api/geocode/json?address=24411+Health+Center+Dr+Suite+200&sensor=false';
$localfile = 'mytempfilename.ext';
// Let's go cURLing...
$ch = curl_init($url);
$fp = fopen($localfile,'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
// Get the data into memory and delete the temp file
$filedata = file_get_contents($localfile);
unlink($localfile);
精彩评论