2014-04-01 64 views
2

我試圖生成一個XML文件的file_get_contents,但誤差都在此file_get_contents() PHP函數,這是我的代碼:未能打開流:權限被拒絕生成XML文件

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; 


    } 

當我嘗試打電話我的網址錯誤來的是行號187是我的代碼file_get_contents()函數。

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錯誤?

+2

你可能didnt設置的權限。嘗試'chmod(「your/path /」,0777)' –

+1

設置完整的權限:chmod -R 777/filepath/ –

+2

設置HTTP URL的權限有點沒有意義,夥計們... – CBroe

回答

13

事實證明,這是我的服務器上的問題:

我跑這條線從終端到reslove它

setsebool -P httpd_can_network_connect on 

感謝您的建議傢伙

+1

我希望我可以upvote這個曾經 - 在過去的一個小時裏,我一直在抨擊防火牆設置,但發現這只是selinux設置的一個問題 –

+0

非常感謝,:)對我來說它是一個很好的幫助。 –

+0

爲我節省了一噸。另外,我在CentOS上試圖連接到同一個盒子上的web服務。 – frostymarvelous

1

我有使用LAMP + Wordpress自行配置的CentOS6主機也出現同樣的問題。 Wordpress wp_remote_get()函數沒有返回結果(並且沒有返回錯誤),也沒有返回PHP file_get_contents()。在主機上執行此操作可解決此問題。

setsebool -P httpd_can_network_connect on 
3

我有同樣的問題,如上述建議,以下爲我工作在CentOS 7

setsebool -P httpd_can_network_connect on 
相關問題