【问题标题】:file_get_contents() connection refused to local file urlfile_get_contents() 连接到本地文件 url 被拒绝
【发布时间】:2015-01-03 01:02:27
【问题描述】:

由于某种原因,file_get_contents 不允许我获取位于同一服务器上的文件。

这是我得到的错误:

file_get_contents(http://www.my-url.com/image.jpg): failed to open stream: Connection refused

我知道我可以使用系统路径来获取文件,但在这种情况下,我需要能够使用 URL 进行测试。

【问题讨论】:

  • 检查你的php.ini,是不是“allow_url_fopen = On”。
  • 如果它们在同一台服务器上,为什么不使用文件系统路径?
  • allow_url_fopen 已经开启,我无法使用系统路径,因为我正在使用需要 URL 的 WordPress 函数
  • 请参考this question希望对您有所帮助。
  • 如果他们在同一台服务器上,那么不要使用成熟的 http 请求。这是非常浪费的。使用本地文件系统路径,例如file_get_contents('/home/sites/my-url.com/html/image.jpg')

标签: php apache file-get-contents


【解决方案1】:

如果您使用的是 url 而不是目录机制,即使您正在打开的文件在您的服务器上,您也需要设置

allow_url_fopen = On

在你的 php.ini 文件中。

【讨论】:

    猜你喜欢
    • 2011-12-19
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2015-07-27
    • 1970-01-01
    • 2011-11-04
    • 2015-07-30
    • 1970-01-01
    相关资源
    最近更新 更多