40 lines
1.5 KiB
PHP
40 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
require_once __DIR__ . '/auth.php'; // ensures login
|
||
|
|
require_once __DIR__ . '/config.php';
|
||
|
|
|
||
|
|
$msg = '';
|
||
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['comic'])) {
|
||
|
|
$title = trim($_POST['title']);
|
||
|
|
$desc = trim($_POST['description']);
|
||
|
|
$file = $_FILES['comic'];
|
||
|
|
|
||
|
|
if ($file['error'] === UPLOAD_ERR_OK && $title) {
|
||
|
|
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
|
||
|
|
$fname = uniqid('comic_') . '.' . $ext;
|
||
|
|
move_uploaded_file($file['tmp_name'], __DIR__ . '/../uploads/' . $fname);
|
||
|
|
|
||
|
|
$stmt = $db->prepare("INSERT INTO comics (title, filename, description) VALUES (:t,:f,:d)");
|
||
|
|
$stmt->bindValue(':t',$title,SQLITE3_TEXT);
|
||
|
|
$stmt->bindValue(':f',$fname,SQLITE3_TEXT);
|
||
|
|
$stmt->bindValue(':d',$desc,SQLITE3_TEXT);
|
||
|
|
$stmt->execute();
|
||
|
|
$msg = "✅ Uploaded '$title'";
|
||
|
|
} else $msg = "Upload failed.";
|
||
|
|
}
|
||
|
|
?>
|
||
|
|
<!DOCTYPE html>
|
||
|
|
<html>
|
||
|
|
<head><title>Upload Comic - MentalNet Funnies</title></head>
|
||
|
|
<body style="background:#111;color:#eee;font-family:monospace;text-align:center">
|
||
|
|
<h1>🧠 Upload Comic</h1>
|
||
|
|
<p><?=htmlspecialchars($msg)?></p>
|
||
|
|
<form method="post" enctype="multipart/form-data">
|
||
|
|
<p><input type="text" name="title" placeholder="Title" required></p>
|
||
|
|
<p><textarea name="description" placeholder="Description"></textarea></p>
|
||
|
|
<p><input type="file" name="comic" accept="image/*" required></p>
|
||
|
|
<p><button type="submit">Upload</button></p>
|
||
|
|
</form>
|
||
|
|
<p><a href="../index.php" style="color:#0ff;">← View Site</a></p>
|
||
|
|
</body>
|
||
|
|
</html>
|
||
|
|
|