file_get_contents函数在获得远程文件时提示Warning: file_get_contents failed to open stream,希望例子能够帮助到各位,希望例子能够帮助到大家。file_get_contents函数在获得远程文件时提示Warning: file_get_contents failed to open stream,希望例子能够帮助到各位,希望例子能够帮助到大家。 在做项目时用 file_get_contents 来获取数据,php 报错 PHP Warning: file_get_contents failed to open stream: no suitable wrapper coul
在做项目时用 file_get_contents 来获取数据,php 报错 PHP Warning: file_get_contents failed to open stream: no suitable wrapper could be found.
最后用了curl来获取数据!
系统:centos 6.5
在错误日志中,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);
可以请求时,忽略错误。可以解决警告信息
				 沃梦达教程
				
			本文标题为:file_get_contents failed to open stream 解决报错问题的办法
 
				
         
 
            
        基础教程推荐
             猜你喜欢
        
	     - php去除deprecated的实例方法 2022-09-02
- PHP采用get获取url汉字出现乱码的解决方法 2024-03-28
- php生成短网址/短链接原理和用法实例分析 2023-04-20
- PHP laravel使用自定义邮件类实现发送邮件 2023-07-03
- PHP字符串函数系列之nl2br(),在字符串中的每个新行 (\n) 之前插入 HTML 换行符br 2024-03-28
- Laravel修改验证提示信息为中文的示例 2023-03-08
- PHP基于反射机制实现自动依赖注入的方法详解 2022-10-02
- php如何获取当前日期和星期 2024-12-06
- Laravel 解决composer相关操作提示php相关异常的问题 2023-03-08
- php+mysql开发的最简单在线题库(在线做题系统)完整案例 2023-01-04
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				