Fix gestione pagina voti in caso di file csv non esistente
This commit is contained in:
6
voti.php
6
voti.php
@@ -14,8 +14,9 @@ class Voto{
|
|||||||
$this->voto = $voto;
|
$this->voto = $voto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$file = fopen("data/voti.csv", "r") or die("Non riesco a leggere il file, controlla che esista");
|
|
||||||
$voti = [];
|
$voti = [];
|
||||||
|
if(file_exists("data/voti.csv")){
|
||||||
|
$file = fopen("data/voti.csv", "r");
|
||||||
|
|
||||||
fgets($file);
|
fgets($file);
|
||||||
while (($linea = fgets($file)) !== false) {
|
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]));
|
array_push($voti, new Voto($campi[0], $campi[1], $campi[2], $campi[3], $campi[4]));
|
||||||
}
|
}
|
||||||
fclose($file);
|
fclose($file);
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -36,7 +38,7 @@ fclose($file);
|
|||||||
<body>
|
<body>
|
||||||
<a href="/">Torna alla pagina principale</a>
|
<a href="/">Torna alla pagina principale</a>
|
||||||
<?php
|
<?php
|
||||||
if(count($voti) == 0){
|
if(count($voti) == 0 or file_exists("data/voti.csv") == false){
|
||||||
echo "<p>Nessun voto caricato</p>";
|
echo "<p>Nessun voto caricato</p>";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|||||||
Reference in New Issue
Block a user