D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
skyconb
/
newsyacine
/
Filename :
add_video.php
back
Copy
<?php // =============================================== // add_video.php (صفحة إضافة فيديو جديد - مع تحميل صورة مصغرة) // =============================================== session_start(); include 'db_connect.php'; // التحقق من تسجيل الدخول والصلاحية if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) { header("Location: login.php"); exit(); } $message = ''; $error = ''; $title = ''; $m3u8_link = ''; $iframe_link = ''; // المسار حيث سيتم تخزين الصور $upload_dir = 'uploads/thumbnails/'; if ($_SERVER["REQUEST_METHOD"] == "POST") { // 1. جلب البيانات من النموذج $title = $_POST['title'] ?? ''; $m3u8_link = $_POST['m3u8_link'] ?? ''; $iframe_link = $_POST['iframe_link'] ?? ''; $thumbnail_url = ''; // سيتم تعيينها بعد نجاح الرفع // 2. التحقق من البيانات الأساسية if (empty($title)) { $error = "الرجاء إدخال عنوان الفيديو."; } elseif (empty($m3u8_link) && empty($iframe_link)) { $error = "يجب إدخال رابط M3U8 (للفيديو المسجل) أو رابط البث المباشر (iframe) على الأقل."; } else { // 3. معالجة تحميل الصورة المصغرة (Thumbnail) if (isset($_FILES['thumbnail']) && $_FILES['thumbnail']['error'] === UPLOAD_ERR_OK) { $file_tmp_path = $_FILES['thumbnail']['tmp_name']; $file_name = $_FILES['thumbnail']['name']; $file_size = $_FILES['thumbnail']['size']; $file_type = $_FILES['thumbnail']['type']; // تنظيف اسم الملف وإنشاء اسم فريد $ext = pathinfo($file_name, PATHINFO_EXTENSION); $new_file_name = uniqid('thumb_', true) . '.' . $ext; $dest_path = $upload_dir . $new_file_name; // التحقق من نوع الملف (لضمان الأمان) $allowed_types = ['image/jpeg', 'image/png', 'image/gif']; if (!in_array($file_type, $allowed_types) || $file_size > 5000000) { // 5MB limit $error = "الصورة غير صالحة. يجب أن تكون JPG/PNG/GIF وبحجم أقل من 5 ميغابايت."; } elseif (!is_writable($upload_dir)) { $error = "خطأ في المجلد: مجلد الرفع غير قابل للكتابة. (".$upload_dir.")"; } elseif (move_uploaded_file($file_tmp_path, $dest_path)) { // نجاح الرفع: تخزين مسار الملف النسبي في قاعدة البيانات $thumbnail_url = $dest_path; } else { $error = "حدث خطأ غير متوقع أثناء نقل ملف الصورة."; } } else { // إذا لم يتم تحميل صورة ولم يكن هناك خطأ حرج (قد يكون تحميل الصورة اختيارياً) // يمكنك إضافة منطق لجعل الصورة إلزامية إذا أردت if (empty($error) && !empty($_POST['has_thumbnail_required'])) { $error = "الرجاء تحديد صورة مصغرة للفيديو."; } } // 4. حفظ البيانات في قاعدة البيانات if (empty($error)) { $sql = "INSERT INTO videos (title, thumbnail_url, m3u8_link, iframe_link, upload_date) VALUES (?, ?, ?, ?, NOW())"; $stmt = $conn->prepare($sql); // ربط المعاملات (ssss تعني 4 سلاسل نصية) $stmt->bind_param("ssss", $title, $thumbnail_url, $m3u8_link, $iframe_link); if ($stmt->execute()) { $_SESSION['message'] = "تم إضافة الفيديو بنجاح."; header("Location: admin.php?section=videos"); exit(); } else { $error = "خطأ في قاعدة البيانات: " . $stmt->error; } $stmt->close(); } } } $conn->close(); ?> <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>إضافة فيديو جديد</title> <style> body { font-family: Tahoma, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; } .container { max-width: 600px; margin: 50px auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); } h1 { text-align: center; color: #2c3e50; border-bottom: 2px solid #eee; padding-bottom: 10px; } label { display: block; margin: 10px 0 5px; font-weight: bold; } input[type="text"], input[type="file"], textarea { width: 100%; padding: 10px; margin-bottom: 20px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } textarea { resize: vertical; height: 100px; } button { background-color: #2ecc71; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; transition: background-color 0.3s; } button:hover { background-color: #27ae60; } .error { color: #e74c3c; background-color: #f8d7da; padding: 10px; border-radius: 4px; margin-bottom: 15px; border: 1px solid #f5c6cb; } .back-link { display: block; text-align: center; margin-top: 20px; color: #3498db; text-decoration: none; } </style> </head> <body> <div class="container"> <h1>إضافة فيديو جديد</h1> <?php if ($error): ?> <div class="error"><?php echo $error; ?></div> <?php endif; ?> <form method="POST" enctype="multipart/form-data"> <input type="hidden" name="has_thumbnail_required" value="1"> <label for="title">عنوان الفيديو:</label> <input type="text" id="title" name="title" required value="<?php echo htmlspecialchars($title); ?>"> <label for="thumbnail">تحميل صورة مصغرة (Thumbnail):</label> <input type="file" id="thumbnail" name="thumbnail" accept="image/jpeg, image/png, image/gif" required> <small style="display: block; margin-top: -15px; margin-bottom: 20px; color: #777;">(مطلوب لمشاركات الفيسبوك - الصيغ المدعومة: JPG, PNG, GIF)</small> <hr style="margin: 30px 0; border-top: 1px dashed #ccc;"> <label for="m3u8_link">رابط M3U8 (للفيديوهات المسجلة - اختياري):</label> <textarea id="m3u8_link" name="m3u8_link"><?php echo htmlspecialchars($m3u8_link); ?></textarea> <label for="iframe_link">رابط البث المباشر (كود iframe كاملاً - اختياري):</label> <textarea id="iframe_link" name="iframe_link" placeholder="ضع كود iframe كاملاً هنا"><?php echo htmlspecialchars($iframe_link); ?></textarea> <button type="submit">إضافة الفيديو</button> </form> <a href="admin.php?section=videos" class="back-link">العودة إلى إدارة الفيديوهات</a> </div> </body> </html>