From fd7fd580dbab6083375a47c44f7812f3f1e0f865 Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Sun, 25 Jan 2026 17:56:41 +0100 Subject: [PATCH] Aggiunta gestione eccezioni in lettura file su pagina voti --- voti.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/voti.php b/voti.php index fe8bc66..207b582 100644 --- a/voti.php +++ b/voti.php @@ -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); } ?>