".jpg", "image/png" => ".png", "image/gif" => ".gif", "application/x-shockwave-flash" => ".swf", ]; if (!is_dir($uploadDir)) mkdir($uploadDir, 0775, true); if (!file_exists($dataFile)) file_put_contents($dataFile, json_encode([])); function loadPosts() { global $dataFile; return json_decode(file_get_contents($dataFile), true) ?: []; } function savePosts($posts) { global $dataFile; file_put_contents($dataFile, json_encode($posts, JSON_PRETTY_PRINT)); generateHTML(); } function h($str) { return htmlspecialchars($str, ENT_QUOTES, "UTF-8"); } function generateHTML() { $posts = array_reverse(loadPosts()); $html = ' Simple Flash Board

/f/ - Flash

New Thread

Subject:
Tag:
File:

Threads

'; foreach ($posts as $p) { $html .= ''; if ($p["replies"]) { $html .= ''; } $html .= ''; } $html .= '
No.NameFileTagSubjectSizeDateReplies
' . h($p["id"]) . ' ' . h($p["name"]) . ' '; if ($p["file"]) { $html .= '[Embed]'; } else { $html .= '—'; } $html .= ' [' . h($p["tag"]) . '] ' . h($p["subject"]) . ' ' . ($p["size"] ? round($p["size"]/1024,2) . " KB" : "—") . ' ' . h($p["date"]) . ' ' . count($p["replies"]) . ' [Reply]
'; foreach ($p["replies"] as $r) { $html .= '
▶ ' . h($r["text"]) . ' (' . h($r["date"]) . ')
'; } $html .= '
Reply:
'; file_put_contents(HTM_FILE, $html); } // This part handles form submissions, nusoi if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["newthread"])) { $posts = loadPosts(); $name = trim($_POST["name"] ?? "Anonymous"); $subject = trim($_POST["subject"] ?? ""); $tag = trim($_POST["tag"] ?? ""); $id = time(); $filename = null; $size = 0; if (!empty($_FILES["file"]["tmp_name"])) { $tmp = $_FILES["file"]["tmp_name"]; $mime = mime_content_type($tmp); $size = $_FILES["file"]["size"]; if (!isset($allowedMimes[$mime])) { die("Invalid file type."); } if ($size > $maxSize) { die("File too large."); } $ext = $allowedMimes[$mime]; $filename = $id . $ext; move_uploaded_file($tmp, "$uploadDir/$filename"); } $posts[] = [ "id" => $id, "name" => $name ?: "Anonymous", "file" => $filename, "tag" => $tag, "subject" => $subject, "size" => $size, "date" => date("m/d/y(D)H:i:s"), "replies" => [] ]; savePosts($posts); // HTML regeneration time header("Location: " . basename(HTM_FILE)); exit; } if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["replyto"])) { $id = intval($_POST["replyto"]); $text = trim($_POST["reply"] ?? ""); if ($text) { $posts = loadPosts(); foreach ($posts as &$p) { if ($p["id"] === $id) { $p["replies"][] = ["text" => $text, "date" => date("m/d/y(D)H:i:s")]; } } savePosts($posts); // HTML regeneration time again } header("Location: " . basename(HTM_FILE)); exit; } generateHTML(); header("Location: " . basename(HTM_FILE)); die("Updating index") exit; ?>