PHP Warning: file_get_contents failed to open stream解决办法

在做项目时用 file_get_contents 来获取数据,php 报错  PHP Warning: file_get_contents failed to open stream: no suitable wrapper could be found.

 

在错误日志中,php报的错误是

Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0

failed to open stream: no suitable wrapper could be found

此警告说服务器阻止访问远程文件,修改php.ini

allow_url_fopen = Off
allow_url_include = Off

改成

allow_url_fopen = On
allow_url_include = On

重启php-fpm或者重启web服务。

如果还是无法解决 的话

windows下处理方法:

c:\windows\php.ini

extension=php_openssl.dll 把前的;去掉,重启iis服务。

linux下处理方法:

/etc/php.ini

extension=php_openssl.dll 把前的;去掉,重启apache服务。


如果上面问题没能解决我的问题,我们可以如下测试。
$context = stream_context_create(array('http'=>array('ignore_errors'=>true)));
$contents = file_get_contents($url, FALSE, $context);

可以请求时,忽略错误。可以解决警告信息

 

$img = file_get_contents('http://www.w3cschool.cn/attachments/day_170216/201702162023331045.png'); 
file_put_contents('1.png',$img); 
echo '<img src="1.png">'; 

 

原文链接:http://www.jquerycn.cn/a_26449

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值