file_get_contents() 错误
我在 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
知道吗?它在我的计算机上运行良好,但当我将其移植到网络服务器时停止运行。
I am using file_get_contents on my PHP and it throws some errors:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的服务器必须具有
allow_url_fopen
属性设置为 true。使用免费的虚拟主机可以解释这一点,因为它通常被禁用以防止滥用。如果您支付了托管费用,请与您的托管商联系,以便他们为您启用它。如果无法更改该设置,请查看 cURL 库。
Your server must have the
allow_url_fopen
property 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.If changing that setting is not an option, then have a look at the cURL library.
您的服务器上的“allow_url_fopen”设置似乎为 false,因此不允许将 URL 与 file_get_contents() 一起使用。
尝试使用 CURL 代替,这是与其他人沟通的更好、更有效的方式服务器。
It seems "allow_url_fopen" setting is false on your server and hence does not allow using URLs with file_get_contents().
Try using CURL instead that is a better and efficient way of communicating with other server.