警告:file_get_contents():https://wrapper在服务器配置中被所有人禁用


Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by all

当我上传带有邮政编码的csv文件时,它将转换并保存纬度和经度。将邮政编码转换为lat,lng时发生的错误。在我的本地主机中,它运行良好。当我在实时服务器中上传时。我收到此错误警告:file_get_contents():https://wrapper在服务器配置中被第29行的/hermes/bosnaweb05a/b1410/ipg.rwdinfotech.com/vw/zipmapping/index.php中的allow_url_fopen=0禁用。我也检查了我的谷歌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];
}

首先,使用此代码检查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');
}
?>

编辑php.ini文件并使用以下代码启用

allow_url_fopen = 1 //0 for Off and 1 for On Flag
  1. 登录您的Cpanel
  2. 在"软件"下单击MultiPHP INI编辑器演示
  3. 单击编辑器模式并选择域演示
  4. 粘贴allow_url_fopen=1并保存

这个解决方案对我很有效,因为我无法访问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;
}

并使用它来代替

file_get_contents($url)

它奏效了。

解决方案在这里有更好的解释,所有的功劳都归功于帖子的创建者。

我遇到了同样的问题,我在谷歌上搜索了这个主题
即使手动上传,我也无法将其从joomla direct 3.9.1更新到3.9.2
原因是在这次更新之前,它迫使我将php版本升级到7.2,所以我从cpanel进行了升级,现在要解决的下一次更新将是:

  1. 登录cpanel
  2. 在软件下查找"MultiPHP INI编辑器"
  3. 选择您的域并选择编辑
  4. 设置:
    "max_execution_time"为90(在矿井30中)
    "memory_limit"为256M(它是由新php仅启用32M!)
    "post_max_size"到100M
    "上传_max_filesize"至100M

因为每个php新版本都设置为默认值。

享受;)

尝试从.htaccess中删除下面的行,并切换到最新版本的PHP

对我来说,这是由以下内容添加到引起的。htaccess:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php70___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

移除它解决了问题,但它在未知的一段时间后再次出现。

我注意到我正在运行(不推荐使用)PHP 7.0,并将其更改为(最新版本)7.4。我向我们的托管提供商发送了一张关于该问题的支持票,他们回复道:

如果您现在选择了PHP7.4,那么它不应该替换这些行更长的时间,因为CloudLinux就是这样做的——它强制使用特定的PHP要通过.htaccess 加载的版本

它在最后一个小时内没有回来,所以祈祷吧。

如果只需要使用CLI运行一次脚本,那么只需添加-d allow_url_fopen=1,即使它在主php.ini中被禁用,例如:

php -d allow_url_fopen=1 script.php

尝试将以下代码添加到您的PHP文件中:

<?php
    ini_set("allow_url_fopen", 1);

问题可能是在服务器上,allow_url_fopen的PHP设置可能配置不同:例如0。如果您有权访问php.ini文件,也可以在该文件中执行同样的操作。

希望这能有所帮助。。。。