PHP'file_get_contents'不能从服务器工作 [英] PHP 'file_get_contents' does not work from server
本文介绍了PHP'file_get_contents'不能从服务器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个托管在雅虎小企业和应用程序
(Java)托管在Rackspace的网站
(PHP)
我从网站到应用程序创建了一个 file_get_contents
。在我的地方工作正常。
这里我使用arequest发送训练列表在 JSON
PHP零件
code> $ trainingArrayJson = file_get_contents('http://mywebapplication.com/publicTraining/getTrainingsAsJson/');
$ trainingArray = json_decode($ trainingArrayJson);
-------
-----
不工作。
如果我这样做
$ trainingArrayJson = file_get_contents ('http:// localhost:8080 / publicTraining / getTrainingsAsJson /');
$ trainingArray = json_decode($ trainingArrayJson);
这很好。
方案
您需要允许
allow_url_fopen
pre>
。有些主机不允许它的安全。
I have a
website
(PHP) hosted in Yahoo small business andapplication
(Java) Hosted in Rackspace.I am making a
file_get_contents
from website to application. which works fine in my local. but when i try the same after deploying it in server does not work.Here i am making arequest which sends list of training in
JSON
format.PHP part
$trainingArrayJson = file_get_contents('http://mywebapplication.com/publicTraining/getTrainingsAsJson/'); $trainingArray = json_decode($trainingArrayJson); ------- -----
this is not working.
if i do
$trainingArrayJson = file_get_contents('http://localhost:8080/publicTraining/getTrainingsAsJson/'); $trainingArray = json_decode($trainingArrayJson);
this works fine.
解决方案You need to allow
allow_url_fopen
in your php.ini config file. Some hosts disallow it for security.
这篇关于PHP'file_get_contents'不能从服务器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文