BLACKSITE
:
216.73.216.169
:
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/gallery.php
<?php require_once __DIR__ . '/../config/db.php'; // Check authentication if (!isset($_SESSION['admin_id'])) { header('Location: login.php'); exit; } // Handle delete if (isset($_GET['delete'])) { $id = (int)$_GET['delete']; $stmt = $pdo->prepare("SELECT image FROM gallery WHERE id = ?"); $stmt->execute([$id]); $g = $stmt->fetch(); if ($g && $g['image'] && file_exists('../uploads/gallery/' . $g['image'])) unlink('../uploads/gallery/' . $g['image']); $pdo->prepare("DELETE FROM gallery WHERE id = ?")->execute([$id]); header('Location: gallery.php?msg=deleted'); exit; } // Handle upload if ($_SERVER['REQUEST_METHOD'] === 'POST') { $caption = trim($_POST['caption'] ?? ''); $project_name = trim($_POST['project_name'] ?? 'Jeddah City'); if (isset($_FILES['images'])) { $uploaded = 0; for ($i = 0; $i < count($_FILES['images']['name']); $i++) { if ($_FILES['images']['error'][$i] === UPLOAD_ERR_OK) { $allowed = ['image/jpeg','image/png','image/webp','image/gif']; if (in_array($_FILES['images']['type'][$i], $allowed)) { $ext = pathinfo($_FILES['images']['name'][$i], PATHINFO_EXTENSION); $image_name = 'gallery_' . time() . '_' . rand(100,999) . '_' . $i . '.' . $ext; move_uploaded_file($_FILES['images']['tmp_name'][$i], '../uploads/gallery/' . $image_name); $stmt = $pdo->prepare("INSERT INTO gallery (image, caption, project_name) VALUES (?,?,?)"); $stmt->execute([$image_name, $caption, $project_name]); $uploaded++; } } } header('Location: gallery.php?msg=uploaded&count=' . $uploaded); exit; } } $admin_page_title = 'Gallery Management'; require_once 'includes/header.php'; $images = $pdo->query("SELECT * FROM gallery ORDER BY created_at DESC")->fetchAll(); ?> <?php if (isset($_GET['msg'])): ?> <div class="alert-dismiss mb-4 px-4 py-3 rounded-xl text-sm font-medium <?= $_GET['msg'] === 'deleted' ? 'bg-red-100 text-red-700' : 'bg-green-100 text-green-700' ?>"> <?= $_GET['msg'] === 'uploaded' ? '✅ ' . ($_GET['count'] ?? '') . ' image(s) uploaded!' : '🗑️ Image deleted!' ?> </div> <?php endif; ?> <!-- Upload Form --> <div class="bg-white rounded-xl shadow-sm p-6 mb-6"> <h3 class="font-semibold text-gray-800 mb-4">Upload Images</h3> <form method="POST" enctype="multipart/form-data" class="space-y-4"> <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">Images</label> <input type="file" name="images[]" accept="image/*" multiple required 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> <label class="block text-sm font-medium text-gray-700 mb-1">Caption</label> <input type="text" name="caption" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm" placeholder="Image caption"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-1">Project</label> <input type="text" name="project_name" value="Jeddah City" class="w-full px-4 py-2.5 border border-gray-300 rounded-xl text-sm"> </div> </div> <button type="submit" class="bg-primary-700 hover:bg-primary-800 text-white px-5 py-2.5 rounded-xl text-sm font-medium transition-colors"><i class="fas fa-upload mr-2"></i>Upload</button> </form> </div> <!-- Gallery Grid --> <div class="flex items-center justify-between mb-4"> <p class="text-gray-500 text-sm"><?= count($images) ?> total images</p> </div> <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4"> <?php if (empty($images)): ?> <div class="col-span-full text-center py-12 text-gray-400 bg-white rounded-xl"><i class="fas fa-images text-3xl mb-2 block"></i>No images uploaded</div> <?php else: ?> <?php foreach ($images as $img): ?> <div class="relative group"> <img src="../uploads/gallery/<?= htmlspecialchars($img['image']) ?>" class="w-full h-40 object-cover rounded-xl" alt="<?= htmlspecialchars($img['caption']) ?>"> <div class="absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity rounded-xl flex items-center justify-center"> <a href="gallery.php?delete=<?= $img['id'] ?>" onclick="return confirm('Delete this image?')" class="bg-red-500 hover:bg-red-600 text-white px-3 py-1.5 rounded-lg text-xs font-medium"><i class="fas fa-trash mr-1"></i>Delete</a> </div> <?php if ($img['caption']): ?> <p class="text-xs text-gray-500 mt-1 truncate"><?= htmlspecialchars($img['caption']) ?></p> <?php endif; ?> </div> <?php endforeach; ?> <?php endif; ?> </div> <?php require_once 'includes/footer.php'; ?>