Aggiunta gestione eccezioni in lettura file su pagina voti
This commit is contained in:
18
voti.php
18
voti.php
@@ -18,12 +18,20 @@ $voti = [];
|
|||||||
if(file_exists("data/voti.csv")){
|
if(file_exists("data/voti.csv")){
|
||||||
$file = fopen("data/voti.csv", "r");
|
$file = fopen("data/voti.csv", "r");
|
||||||
|
|
||||||
fgets($file);
|
try{
|
||||||
while (($linea = fgets($file)) !== false) {
|
fgets($file);
|
||||||
$campi = explode(",", $linea);
|
while (($linea = fgets($file)) !== false) {
|
||||||
array_push($voti, new Voto($campi[0], $campi[1], $campi[2], $campi[3], $campi[4]));
|
$campi = explode(",", $linea);
|
||||||
|
array_push($voti, new Voto($campi[0], $campi[1], $campi[2], $campi[3], $campi[4]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception $e){
|
||||||
|
http_response_code(500);
|
||||||
|
echo "Errore: " . $e->getMessage();
|
||||||
|
}
|
||||||
|
finally{
|
||||||
|
fclose($file);
|
||||||
}
|
}
|
||||||
fclose($file);
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user