Fix gestione pagina voti in caso di file csv non esistente
This commit is contained in:
16
voti.php
16
voti.php
@@ -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) {
|
||||
$campi = explode(",", $linea);
|
||||
array_push($voti, new Voto($campi[0], $campi[1], $campi[2], $campi[3], $campi[4]));
|
||||
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{
|
||||
|
||||
Reference in New Issue
Block a user