file_get_contents generating error 500

0

I have a file which gives file_get_contents in files . PHP can see the files because file_exists works fine. However, if I give file_get_contents in the same file as file_exists PHP returns me:

  

error 500 (internal to the server).

<?php 
date_default_timezone_set('America/Sao_Paulo'); $jogosF = 1; $datadehj = date("Y-m-d"); $horaAgora = date("H:i"); $array = array(); $tempo = (10 * 60); while(file_exists("../../../txts/bkpjogosF". $jogosF .".json")) {
$conteudo = file_get_contents("../../../txts/bkpjogosF". $jogosF .".json");
$conteudo = json_decode($conteudo);

foreach ($conteudo->data as $jogosDia) {
    if($jogosDia->odds->data != null) {
        $dataInicio = $jogosDia->starting_date;
        $horaInicio = $jogosDia->starting_time;
        if ($datadehj == $dataInicio && ((strtotime($horaAgora) + $tempo) < strtotime($horaInicio))) {
            $idMatch = $jogosDia->id;
            $timeCasa = $jogosDia->homeTeam->name;
            $escudoCasa = $jogosDia->homeTeam->logo;
            $timeFora = $jogosDia->awayTeam->name;
            $escudoFora = $jogosDia->awayTeam->logo;
            foreach ($jogosDia->odds->data as $oddses) {
                foreach ($oddses->types->data as $joOdds) {
                    if ($joOdds->type == "1x2") {
                        $bookmakerId = $oddses->bookmaker_id;
                        foreach ($joOdds->odds->data as $jogum) {
                            switch ($jogum->label) {
                                case 1:
                                $cotationC = $jogum->value;
                                break;
                                case 2:
                                $cotationF = $jogum->value;
                                break;
                                case "X":
                                $cotationEmp = $jogum->value;
                                break;
                            }
                        }
                        break 2;
                    }
                }
            }
            $datas = new DateTime($dataInicio);
            $horas = new DateTime($horaInicio);
            $horaInicio = $horas->format('H:i');
            $dataInicio = $datas->format('d/m/Y');
            $array[] = array(
            "horaI" => $horaInicio,
            "DataI" => $dataInicio,
            "timeCasa" => $timeCasa,
            "timeFora" => $timeFora,
            "idPartida" => $idMatch,
            "cotTimeC" => $cotationC,
            "cotEmp" => $cotationEmp,
            "cotTimeF" => $cotationF,
            "escudoC" => $escudoCasa,
            "escudoF" => $escudoFora,
            "bookmaker" => $bookmakerId
            );
        }
    }
}
$jogosF++;
fclose($handle); } $sorteador = usort($array, "Meusort"); echo json_encode($array); function Meusort($a, $b) { if($a == $b) { return 0; } return ($a<$b)?-1:1; } ?>

Note: The folder on the server has chmod -R 777 file, that is, full permission. I already tried using fopen , and gave the same error.
In LOCALHOST with XAMPP it works.

    
asked by anonymous 12.04.2017 / 16:30

1 answer

0

file_get_contents is a function that depending on how you use it may represent a security hole, so its use is enabled by php.ini

If you use it without enabling it in php.ini it will return this 500 error.

To enable change:

allow_url_fopen = 1

But HIGH is recommended to use CURL instead of this function.

function get_content($URL){
    $ch = curl_init();
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_URL, $URL);
      $data = curl_exec($ch);
      curl_close($ch);
      return $data;
}

Usage: echo get_content('http://example.com');

    
12.04.2017 / 16:47