Aggiunta gestione eccezioni in lettura file su pagina voti

This commit is contained in:
2026-01-25 17:56:41 +01:00
parent 6135250f30
commit fd7fd580db

View File

@@ -18,12 +18,20 @@ $voti = [];
if(file_exists("data/voti.csv")){
$file = fopen("data/voti.csv", "r");
fgets($file);
while (($linea = fgets($file)) !== false) {
$campi = explode(",", $linea);
array_push($voti, new Voto($campi[0], $campi[1], $campi[2], $campi[3], $campi[4]));
try{
fgets($file);
while (($linea = fgets($file)) !== false) {
$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);
}
?>