【问题标题】:500 Error: https:// wrapper is disabled in the server configuration by allow_url_fopen=0 when using file_get_contents() [duplicate]500错误:使用file_get_contents()时,服务器配置中的https://包装器被allow_url_fopen = 0禁用[重复]
【发布时间】:2020-01-24 07:25:43
【问题描述】:

我正在尝试使用 API 在网站上显示 youtube 视频。为了从 youtube 获取数据,我正在使用 file_get_contents 并解码接收到的数据,我正在使用 json_decode() 但这些函数都不起作用。当我编写以下函数时:

file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.'')

我收到 500 错误。为什么我收到内部服务器错误?

而且,在错误日志文件中我得到了这个

[2020-01-24 12:32:20] production.ERROR: file_get_contents(): https:// wrapper is disabled in server configuration by allow_url_fopen=0 (查看:/home/project/project_laravel/resources/ views/index.blade.php) {"exception":"[object] (ErrorException(code: 0): file_get_contents(): https:// wrapper is disabled in server configuration by allow_url_fopen=0 (View: /home/项目/project_laravel/resources/views/index.blade.php)在/home/project/project_laravel/storage/framework/views/2ef7c353b55ce1b10f018d5d4c745d8de5c15831.php:91,ErrorException(代码:0):file_get_contents():https://wrapper在服务器配置中被 /home/project/project_laravel/storage/framework/views/2ef7c353b55ce1b10f018d5d4c745d8de5c15831.php:91 的 allow_url_fopen=0 禁用) [堆栈跟踪]

在研究过程中,我在 StackOverflow Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by all 上尝试了这个答案,用户建议我们启用 allow_url_fopen,但是我的 php.ini 中没有 allow_url_fopen=0。甚至在添加之后 allow_url_fopen = 1allow_url_include = 1 我仍然收到此错误。

【问题讨论】:

  • 请发布日志错误消息。
  • 请编辑您的帖子并包含错误信息
  • @TsaiKoga 我收到 500 错误页面。
  • 是的,所以您需要发布错误消息。尝试在 storage/logs/laravel.log 中找到它
  • 您可以使用 iframe 在网页上显示 youtube 视频。

标签: php laravel file-get-contents


【解决方案1】:

根据这个答案Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by all在php.ini中启用allow_url_fopen对我没有帮助。

当我再次搜索这个问题的解决方案时,我发现这篇文章启用allow_url_fopen

但是,由于我使用的是共享主机,支持团队对我说,php中的这个功能存在安全风险,他们没有在共享服务器环境中启用此功能,只能在我自己的风险下启用我在 vps 服务器上运行。

因此,为了通过 API 获取 YouTube 数据,我必须使用 cURL 函数,它对我有用。

【讨论】:

    猜你喜欢
    • 2017-11-24
    • 2019-03-06
    • 2018-01-22
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 2011-10-16
    • 2014-03-07
    相关资源
    最近更新 更多