【问题标题】:file_get_contents() errorfile_get_contents() 错误
【发布时间】:2011-09-26 22:34:01
【问题描述】:

我在我的 PHP 上使用 file_get_contents,它会抛出一些错误:

我的代码

#try to fetch from remote
$this->remotePath = "http://some-hostname.com/blah/blah.xml
$fileIn = @file_get_contents($this->remotePath);

错误:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /virtual/path/to/file/outputFile.php on line 127

Warning: file_get_contents(https://some-host-name/data/inputFile.xml) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /virtual/path/to/file/outputFile.php on line 127

有什么想法吗?它在我的计算机上运行良好,但在我将其移植到网络服务器时停止运行。

【问题讨论】:

  • 顺便说一句,既然要加载xml,请在设置allow_url_fopen后使用simplexml_load_file函数。

标签: php file-get-contents


【解决方案1】:

您的服务器上的“allow_url_fopen”设置似乎是错误的,因此不允许使用带有 file_get_contents() 的 URL。

尝试改用CURL,这是与其他服务器进行通信的更好、更有效的方式。

【讨论】:

    【解决方案2】:

    您的服务器必须将allow_url_fopen 属性设置为true。使用免费的虚拟主机可以解释这一点,因为它通常被禁用以防止滥用。如果您支付了托管费用,请与您的主机联系,以便他们为您启用它。

    如果无法更改该设置,请查看 cURL 库。

    【讨论】:

    • 你知道有什么办法可以解决这个问题,因为该文件来自远程服务器,而不是来自我的内部服务器。
    • 您可以通过 ini_set('allow_url_fopen', 1) 自行完成,但也很有可能被锁定。
    • 我的主机将allow_url_fopen 设置为关闭但启用了curl。这在多大程度上有意义(从他们的角度来看)?
    猜你喜欢
    • 2011-02-27
    • 2019-02-01
    • 1970-01-01
    • 2012-01-02
    • 2015-07-05
    • 1970-01-01
    • 2017-09-30
    • 2012-10-28
    相关资源
    最近更新 更多