Fix gestione pagina voti in caso di file csv non esistente

This commit is contained in:
2026-01-25 17:45:34 +01:00
parent 748e03249e
commit da15aa6779

View File

@@ -14,8 +14,9 @@ class Voto{
$this->voto = $voto;
}
}
$file = fopen("data/voti.csv", "r") or die("Non riesco a leggere il file, controlla che esista");
$voti = [];
if(file_exists("data/voti.csv")){
$file = fopen("data/voti.csv", "r");
fgets($file);
while (($linea = fgets($file)) !== false) {
@@ -23,6 +24,7 @@ while (($linea = fgets($file)) !== false) {
array_push($voti, new Voto($campi[0], $campi[1], $campi[2], $campi[3], $campi[4]));
}
fclose($file);
}
?>
<!DOCTYPE html>
@@ -36,7 +38,7 @@ fclose($file);
<body>
<a href="/">Torna alla pagina principale</a>
<?php
if(count($voti) == 0){
if(count($voti) == 0 or file_exists("data/voti.csv") == false){
echo "<p>Nessun voto caricato</p>";
}
else{