1. 程式人生 > >PHP Warning: file_get_contents failed to open stream解決辦法

PHP 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 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); 可以請求時,忽略錯誤。可以解決警告資訊