I have a file php which gives file_get_contents
in files json .
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.