file_get_contents()在Linux中不起作用


file_get_contents() not working in Linux

可能重复:
file_get_content无法打开流:连接被拒绝

file_get_content函数在Linux vqs332.pair.com 2.6.32-33-server上不起作用。要么我需要更改php.ini中的任何设置,要么是其他问题。我使用这个函数从地址中获取纬度和经度(动态(。

file_get_contents("http://maps.google.com/maps/api/geocode/json?address=24411+Health+Center+Dr+Suite+200&sensor=false");

Plz引导我。

问题可能是您的主机禁用了allow_url_fopen。这在共享托管环境中很常见,是一种明智的安全预防措施。

为了解决这个问题,您必须将带有cURL的文件下载到本地路径并在本地使用。

例如

// 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);