【问题标题】:Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by all警告:file_get_contents(): https:// 包装器在服务器配置中被所有人禁用
【发布时间】:2016-08-25 10:24:08
【问题描述】:

当我上传带有邮政编码的 csv 文件时,它会转换并保存纬度和对数。将邮政编码转换为 lat,lng 时发生的错误。在我的本地主机中,它工作正常。当我在实时服务器中上传时。我收到此错误 Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /hermes/bosnaweb05a/b1410/ipg.rwdinfotechcom/vw/zipmapping/index.php 在线29 。我也检查了我的 google 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.INI 而不是代码。

标签: php


【解决方案1】:

首先,用这段代码检查你的 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
allow_url_include = 1 //0 for Off and 1 for On Flag

【讨论】:

    【解决方案2】:
    1. 登录您的 Cpanel
    2. 在软件下点击 MultiPHP INI 编辑器 demo
    3. 点击编辑模式并选择域 demo
    4. 粘贴 allow_url_fopen = 1 并保存

    【讨论】:

    • 我这样做了,但仍然收到相同的消息。是否还有其他步骤需要完成才能生效?
    • @primehalo 转到 WHM > MultiPHP INI Editor > 选择 PHP 版本并将 allow_url_fopen 设置为 Enabled。
    • @WHM Mine 没有该选项
    • 在我的 cPanel 中有一个复选框可以在(软件)选择 PHP 版本 > 选项(顶部的选项卡)中启用allow_url_fopen,尽管如果这不能解决您看到的my answer below .
    【解决方案3】:

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

    它成功了。

    解决方案更好地解释here,所有功劳归于帖子的创建者。

    【讨论】:

      【解决方案4】:

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

      1. 登录cpanel
      2. 在软件下找到“MultiPHP INI Editor”
      3. 选择您的域并选择编辑
      4. 设置:
        “max_execution_time” 到 90(在我的 30 中)
        “memory_limit”到 256M(它是由新的 php 启用的,仅 32M !)
        “post_max_size”为 100M
        "upload_max_filesize" 到 100M

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

      享受;)

      【讨论】:

        【解决方案5】:

        尝试从 .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。我向我们的托管服务提供商发送了一张关于该问题的支持票,他们回复了:

        如果您现在选择了 PHP 7.4,它不应该替换这些行 更长,因为这就是 CloudLinux 所做的 - 它强制特定的 PHP 要通过 .htaccess 加载的版本

        最后一个小时还没有回来,所以祈祷。

        【讨论】:

          【解决方案6】:

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

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

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

          希望这会有所帮助....

          【讨论】:

          • allow_url_fopen can NOT 可以更改在脚本中 这个ini设置需要在php.inihttpd.conf中设置为changed .
          猜你喜欢
          • 2017-11-24
          • 2017-08-14
          • 1970-01-01
          • 1970-01-01
          • 2011-10-16
          • 2018-01-22
          • 2019-03-06
          • 2014-06-10
          相关资源
          最近更新 更多