<?php
$csv_file = '/var/www/thumbs.csv';

// Read current count
if (($handle = fopen($csv_file, 'r')) !== false) {
    fgetcsv($handle); // skip header
    $row = fgetcsv($handle);
    $count = intval($row[0]);
    fclose($handle);
} else {
    $count = 0;
}

// Handle thumbs up click
if (isset($_POST['thumbs_up'])) {
    $count++; // increment

    // Write new count back to CSV
    if (($handle = fopen($csv_file, 'w')) !== false) {
        fputcsv($handle, ['count']);
        fputcsv($handle, [$count]);
        fclose($handle);
    }
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Thumbs Up Counter</title>
</head>
<body>
    <h1>If you recently got saved, <br>hit the thumbs up!</h1>
    <form method="POST">
        <button type="submit" name="thumbs_up">👍</button>
    </form>
    <p>Total Thumbs Up: <?php echo $count; ?></p>
</body>
</html>
