无法打开流:权限被拒绝,生成了XML FILE的file_get_contents [英] failed to open stream: Permission denied file_get_contents which generates XML FILE

查看:171
本文介绍了无法打开流:权限被拒绝,生成了XML FILE的file_get_contents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试生成XML文件,但是此 file_get_contents() PHP函数出现错误,这是我的代码:

I am trying to generating an XML file, but error come in this file_get_contents() PHP function, this is my code:

 function mobile_login1($P1, $P2)
{
    $url = 'myURL';
    $data = array(
        'username' => $P1,
        'password' => $P2);

    // use key 'http' even if you send the request to https://...
    $options = array(
        'http' => array(
            'header'  => "Content-type: application/x-www-form-urlencoded",
            'method'  => 'POST',
            'content' => http_build_query($data),
        ),
    );
    $context  = stream_context_create($options);
    $json_data = file_get_contents($url, false, $context);


            $decode = json_decode($json_data);

            //print_r ($decode[0]);
            //

            foreach($decode as $row)
            {
                $data[] = array("Message" => $row->msg);


            }


            //print_r ($data[0]['Message']);

            $msg = $data[0]['Message'];

            if ($msg == 'Incorrect username/password')
            {


                 $this->response['ResponseCode'] = "1000";
                 $this->response['ResponseMessage'] = $msg;
                 $this->response['ResponseData'] = $data;
            }

            else
            {
                if($decode != null)
                {
                    foreach($decode as $row)
                    {
                        $data[] = array("AccountId" => $row->a_id,
                                        "PersonalId" => $row->p_id,
                                        "FullName" => $row->full_name,
                                        "AccountName" => $row->a_name,
                                        "AccountType" => $row->a_type,
                                        "WalletBalance" => $row->wallet_balance,
                                        "PersonalAddress" => $row->p_add,
                                        "CompanyName" => $row->company_name,
                                        "CompanyAddress" => $row->company_add,
                                        "Fax" => $row->fax,  
                                        "PersonalMobile" => $row->p_mobile,
                                        "PersonalTelephone" => $row->p_tel,
                                        "Limit" => $row->limit,
                                        "Role" => $row->role,
                                        "AccountMobile" => $row->a_telno);
                    }


                    $this->response['ResponseCode'] = "0000";
                    $this->response['ResponseMessage'] = "successful";
                    $this->response['ResponseData'] = $data;
                }
                else
                {
                    $this->response['ResponseCode'] = "1000";
                    $this->response['ResponseMessage'] = "no records found";
                }   
            }
           //return $json_data;


    }

当我尝试调用URL错误时,行号187是我的 file_get_contents()函数的代码.

when i try to call my URL error come is the Line Number 187 is the code where my file_get_contents() function.

A PHP Error was encountered Severity: Warning Message: 
file_get_contents(http://myURL/mobile_login): failed to open stream: Permission denied 
Filename: models/accounts_model.php Line Number: 187

这是服务器故障还是PHP错误?

推荐答案

原来是我的服务器上有问题:

it turns out it was a problem with on my server:

我从终端运行此行以对其进行重播

I ran this line from the terminal to reslove it

setsebool -P httpd_can_network_connect on

谢谢你的建议

这篇关于无法打开流:权限被拒绝,生成了XML FILE的file_get_contents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆