BLACKSITE
:
216.73.216.140
:
199.188.200.160 / jeddahhousingltd.com
:
Linux server383.web-hosting.com 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
:
/
home
/
jeddveug
/
www
/
admin
/
Upload File:
files >> /home/jeddveug/www/admin/blog_add.php
<?php require_once __DIR__ . '/../config/db.php'; // Check authentication if (!isset($_SESSION['admin_id'])) { header('Location: login.php'); exit; } $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = trim($_POST['title'] ?? ''); $content = trim($_POST['content'] ?? ''); $author = trim($_POST['author'] ?? 'Admin'); $publish_date = $_POST['publish_date'] ?? ''; $status = $_POST['status'] ?? 'draft'; $meta_title = trim($_POST['meta_title'] ?? ''); $meta_description = trim($_POST['meta_description'] ?? ''); if (!$title) $errors[] = 'Title is required.'; // Generate slug $slug = strtolower(preg_replace('/[^a-zA-Z0-9]+/', '-', $title)); $slug = trim($slug, '-'); // Ensure unique slug $check = $pdo->prepare("SELECT COUNT(*) FROM blogs WHERE slug = ?"); $check->execute([$slug]); if ($check->fetchColumn() > 0) { $slug .= '-' . time(); } $image_name = ''; if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $allowed = ['image/jpeg','image/png','image/webp','image/gif']; if (in_array($_FILES['image']['type'], $allowed)) { $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); $image_name = 'blog_' . time() . '_' . rand(100,999) . '.' . $ext; move_uploaded_file($_FILES['image']['tmp_name'], '../uploads/blogs/' . $image_name); } else { $errors[] = 'Invalid image format.'; } } if (empty($errors)) { $stmt = $pdo->prepare("INSERT INTO blogs (title, slug, content, image, author, publish_date, status, meta_title, meta_description) VALUES (?,?,?,?,?,?,?,?,?)"); $stmt->execute([$title, $slug, $content, $image_name, $author, $publish_date ?: null, $status, $meta_title, $meta_description]); header('Location: blogs.php?msg=added'); exit; } } $admin_page_title = 'Add Blog Post'; require_once 'includes/header.php'; ?> <div class="max-w-3xl"> <a href="blogs.php" class="text-sm text-primary-600 hover:text-primary-800 mb-4 inline-flex items-center"><i class="fas fa-arrow-left mr-2"></i> Back to Blogs</a> <?php if (!empty($errors)): ?> <div class="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-xl mb-5 text-sm"> <?php foreach ($errors as $err): ?><p>• <?= htmlspecialchars($err) ?></p><?php endforeach; ?> </div> <?php endif; ?> <form method="POST" enctype="multipart/form-data" class="bg-white rounded-xl shadow-sm p-6 space-y-5"> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Title <span class="text-red-500">*</span></label> <input type="text" name="title" required value="<?= htmlspecialchars($title ?? '') ?>" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Content</label> <textarea name="content" rows="10" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm"><?= htmlspecialchars($content ?? '') ?></textarea> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Featured Image</label> <input type="file" name="image" accept="image/*" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm file:mr-4 file:py-1 file:px-3 file:rounded-lg file:border-0 file:bg-primary-50 file:text-primary-700 file:font-medium file:text-sm"> </div> <div class="grid grid-cols-1 sm:grid-cols-3 gap-4"> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Author</label> <input type="text" name="author" value="<?= htmlspecialchars($author ?? 'Admin') ?>" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Publish Date</label> <input type="date" name="publish_date" value="<?= htmlspecialchars($publish_date ?? date('Y-m-d')) ?>" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Status</label> <select name="status" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm"> <option value="draft">Draft</option> <option value="publish">Publish</option> </select> </div> </div> <hr class="my-2"> <p class="text-xs text-gray-500 font-semibold uppercase tracking-wider">SEO Settings</p> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Meta Title</label> <input type="text" name="meta_title" value="<?= htmlspecialchars($meta_title ?? '') ?>" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm" placeholder="SEO title (max 60 chars)"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Meta Description</label> <textarea name="meta_description" rows="2" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm" placeholder="SEO description (max 160 chars)"><?= htmlspecialchars($meta_description ?? '') ?></textarea> </div> <button type="submit" class="bg-primary-700 hover:bg-primary-800 text-white px-6 py-2.5 rounded-xl text-sm font-medium transition-colors"><i class="fas fa-plus mr-2"></i>Create Post</button> </form> </div> <?php require_once 'includes/footer.php'; ?>