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")){
|
||||
$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);
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user