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,15 +14,17 @@ 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) {
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]));
}
fclose($file);
}
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{