当我上传带有zipcode的csv文件时,它将转换并保存纬度和逻辑.将zipcode转换为lat,lng时发生的错误.在我的localhost工作正常.当我在实时服务器上传时.我收到此错误警告:在第29行的/hermes/bosnaweb05a/b1410/ipg.rwdinfotechcom/vw/zipmapping/index.php中,allow_url_fopen = 0在服务器配置中禁用了file_get_contents():https://包装器.我也检查了我的谷歌API密钥.我无法添加php.ini文件.如果我上传php.ini文件,则显示内部服务器错误.
Here my code
function getLnt($zip){
$url = "https://maps.googleapis.com/maps/api/geocode/json?key=AIzaSyDEGgYDar8y3Bx-1FpY3hq6ON4LufoRK60&address=
".urlencode($zip)."&sensor=false";
$result_string = file_get_contents($url);
$result = json_decode($result_string, true);
$result1[]=$result['results'][0];
$result2[]=$result1[0]['geometry'];
$result3[]=$result2[0]['location'];
return $result3[0];
}Run Code Online (Sandbox Code Playgroud)
Sar*_*ana 27
首先,使用此代码检查PHP文件,然后在php.ini文件中启用fopen
<?php
if( ini_get('allow_url_fopen') ) {
die('allow_url_fopen is enabled. file_get_contents should work well');
} else {
die('allow_url_fopen is disabled. file_get_contents would not work');
}
?>
Run Code Online (Sandbox Code Playgroud)
编辑php.ini文件并使用下面的代码启用
allow_url_fopen = 1 //0 for Off and 1 for On Flag
allow_url_include = 1 //0 for Off and 1 for On Flag
Run Code Online (Sandbox Code Playgroud)
小智 5
这个解决方案对我有用,因为我无法访问 php.ini 文件。
我添加了这个功能:
function curl_get_file_contents($URL)
{
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
Run Code Online (Sandbox Code Playgroud)
并用它代替
file_get_contents($url)
它奏效了。
解决方案在这里得到了更好的解释,所有功劳都归功于帖子的创建者。