Pith - miter
<?php
declare(strict_types=1);
session_start();

if (empty($_SESSION['miter'])) {
header('Location: ../../index.php');
exit;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// delete file + entry
$txt_file = "tenon_inserts.txt";
if (file_exists($txt_file) && is_file($txt_file)) {
unlink($txt_file);
}

// get post
$more_butt_post = $_POST["more_butt"] ?? '';

include '../admin/otc.php';

// errors
$log_file = __DIR__ . '/../admin/log.txt'; 

$log_custom_error = function($message) use ($log_file, $o_date) {
$error_log_data = ($o_date ?? ' ') . " -- " . $message . PHP_EOL;
file_put_contents($log_file, $error_log_data, FILE_APPEND | LOCK_EX);
};

if (empty($txt_file)) { 
$log_custom_error("Error: File path is empty.");
header('Location: ../../index.php');
exit;
}

$tenon_dir = dirname($txt_file);
if (!is_dir($tenon_dir)) { 
$log_custom_error("Error: Dir $tenon_dir does not exist.");
header('Location: ../../index.php');
exit; 
}
if (!is_writable($tenon_dir)) { 
$log_custom_error("Error: Dir $tenon_dir is not writable.");
header('Location: ../../index.php');
exit; 
}

// create and write
try {
$write_status = file_put_contents($txt_file, $more_butt_post, LOCK_EX);
if ($write_status === false) { 
throw new Exception("Failed to write stream."); 
}
} catch (\Throwable $e) { 
$log_custom_error("Exception: " . $e->getMessage());
}

header("location:../../index.php?user=tenon_inserts");
exit;
} else {
header('Location: ../../index.php');
exit;
}
?>