php file_get_contents() 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6551379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:42:28  来源:igfitidea点击:

file_get_contents() error

phpfile-get-contents

提问by Tu Hoang

I am using file_get_contents on my PHP and it throws some errors:

我在我的 PHP 上使用 file_get_contents 并且它抛出了一些错误:

My code

我的代码

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

The errors:

错误:

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

Any idea? It worked fine in my computer but stopped working when I ported it to the web server.

任何的想法?它在我的计算机上运行良好,但当我将其移植到 Web 服务器时停止工作。

回答by Tim Cooper

Your server must have the allow_url_fopenproperty set to true. Being on a free webhost explains it, as it's usually disabled to prevent abuse. If you paid for your hosting, get in contact with your host so they can enable it for you.

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

If changing that setting is not an option, then have a look at the cURLlibrary.

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

回答by Abhay

It seems "allow_url_fopen" setting is false on your server and hence does not allow using URLs with file_get_contents().

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

Try using CURLinstead that is a better and efficient way of communicating with other server.

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