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

In doing project to obtain data with file_get_contents, php error PHP Warning: file_get_contents failed to open stream: no suitable wrapper could be found.

 

In the error log, php error is reported

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

This warns that the server blocks access to remote files, modify the php.ini

The

allow_url_fopen = Off
allow_url_include = Off

Change

allow_url_fopen = On
allow_url_include = On

Restart php-fpm or restart the web service.

If you still can not solve it

the windows approach:

c: \ windows \ php.ini

the front of extension = php_openssl.dll; removed iis restart the service.

linux the processing method:

/etc/php.ini

the front of extension = php_openssl.dll; removed restart apache service.


If the above problem could not solve my problem, we can test as follows.
stream_context_create context = $ (Array ( 'HTTP' => Array ( 'ignore_errors' => to true)));
$ Contents = file_get_contents ($ URL, FALSE, $ context);

When can request, ignore the error. A warning message can be resolved

 

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

 

Original link: http://www.jquerycn.cn/a_26449

Guess you like

Origin blog.csdn.net/mysteryflower/article/details/92798326