36439-vm/upload.php
2025-11-28 19:14:48 +00:00

85 lines
3.2 KiB
PHP

<?php
session_start();
require_once __DIR__ . '/db/config.php';
// If the user is not logged in, redirect them to the login page.
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$error_message = '';
$success_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$title = $_POST['title'] ?? '';
$description = $_POST['description'] ?? '';
$video_url = $_POST['video_url'] ?? '';
if (empty($title) || empty($description) || empty($video_url)) {
$error_message = 'Please fill in all fields, including the Video URL.';
} else {
try {
$pdo = db();
$stmt = $pdo->prepare(
"INSERT INTO videos (user_id, title, description, video_url, creator, upload_date, status) VALUES (?, ?, ?, ?, ?, ?, 'pending')"
);
$stmt->execute([
$_SESSION['user_id'],
$title,
$description,
$video_url,
$_SESSION['username'],
date('Y-m-d')
]);
header("Location: index.php?upload=success");
exit;
} catch (PDOException $e) {
$error_message = 'An error occurred while uploading your video. Please try again later.';
error_log('Upload failed: ' . $e->getMessage());
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Video | MyTube</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="container mt-5">
<h2>Upload a New Video</h2>
<p>Your video will be submitted for approval and will not be public until an admin reviews it.</p>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<form method="POST" action="upload.php">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3" required></textarea>
</div>
<div class="mb-3">
<label for="video_url" class="form-label">Video URL</label>
<input type="url" class="form-control" id="video_url" name="video_url" required>
<small class="form-text text-muted">Please provide a direct link to the video (e.g., a YouTube embed link).</small>
</div>
<button type="submit" class="btn btn-primary">Submit for Approval</button>
<a href="index.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</body>
</html>