Update tags index to handle issue # 9

Now checks for the file and either copies a backup or creates a blank
file.
This commit is contained in:
20xd6 2022-07-26 13:06:52 -04:00
parent 25f1887590
commit dd3405137f

18
blog/by_tag/index.php Normal file → Executable file
View File

@ -32,8 +32,7 @@
//} //}
//echo "</ul>\n"; //echo "</ul>\n";
//} //}
function read_tags($tags_file){
# Tags rewrite
$tags_csv = array_map('str_getcsv', file('tags.csv')); $tags_csv = array_map('str_getcsv', file('tags.csv'));
$tags_rows = sizeof($tags_csv); $tags_rows = sizeof($tags_csv);
$tags_coloums = sizeof($tags_csv[0]); $tags_coloums = sizeof($tags_csv[0]);
@ -64,5 +63,20 @@
$coloum_number++; $coloum_number++;
} }
echo "</ul>\n"; echo "</ul>\n";
}
# Tags rewrite
if (file_exists('tags.csv')){
read_tags('tags.csv');
} elseif( file_exists('tags.csv.bak') ){
if (copy('tags.csv.bak', './tags.csv')) {
read_tags('tags.csv');
}
}else {
$empty_csv = fopen("tags.csv", "w") or die("Cannot write new tags.csv file.");
fwrite($empty_csv, "");
fclose($empty_csv);
}
include_once ($_SERVER['DOCUMENT_ROOT'].'/common/php/footer.php'); include_once ($_SERVER['DOCUMENT_ROOT'].'/common/php/footer.php');
?> ?>