2016-11-21 3 views
4

私はサッカーリーグのAPIを使用していますので、必要なデータが返されました。しかし、それは今、突然すべての作業を停止し、なぜわからないのですか?file_get_contentsにはデータが返されません

class leagueTable { 
    public $data; 
    public $baseUri; 
    public $config; 
    public $tr; 

    public function __construct($payload) { 
     $this->data = $payload; 
     $this->config = parse_ini_file('config.ini', true); 
     $this->baseUri = $this->config['baseUri']; 
     $this->writeTable(); 
    } 

    public function writeTable() { 
     $resource = 'soccerseasons/' . $this->data . '/leagueTable'; 
     $response = file_get_contents($this->baseUri . $resource, false, stream_context_create($this->reqPrefs)); 

     if ($response == "") { 
     echo "Unable to retrieve data, please contact the administrator!<br /> 
      <a target='_blank' href='".$this->baseUri.$resource."'>JSON</a>"; 
     } 
     $result = json_decode($response); 

私は$this->baseUri . $resourceをエコーし​​た場合のfile_get_contentsは内容を取得することはできませんなぜ私は働いlinkを取得しますか?

See the page here too.

+0

stream_contextの目的は何ですか?あなたのサンプルコードでは、 '$ this-> reqPrefs'はnullなので、重複しているようです。また、 'ini_get( 'allow_url_fopen')の値が1であることを確認してください。 –

答えて

1

さて私は

<?php 
$response = file_get_contents('http://api.football-data.org/v1/soccerseasons/426/leagueTable'); 
$result = json_decode($response); 
var_dump($result); 

になるこのダウン易しく書き直さそして、あなたが期待しているとして、それは私の全体の大惨事を得ました。 それがあなたに役立つかどうかは不明です。

+0

うーん、うまくいけば、私は混乱しているのです! –

+0

オレが言っているように何か変わってしまった...しかし、絶対に確実であるように、私は上記のように試してみました。 – TimBrownlaw

+0

これはおそらく@ブリジンが何かに乗っている... – TimBrownlaw

0

管理者がphp.iniファイルの機能(file_get_contents)を無効にしている可能性がありますか?あなたはあなたのPHP情報ページを印刷し、それを調べるべきです。

+0

すぐにそれを試してみると、それは私のホスティングにあったが、私は設定を変更していない。 –

+1

これは@Brijin http:// stackoverflow .com/questions/19024349/php-file-get-contents-do-not-work-from-server – TimBrownlaw

関連する問題