<?php
// File: admin/hapus_galeri.php
session_start();
if (!isset($_SESSION['admin'])) {
  header("Location: login.php");
  exit;
}

include '../config/koneksi.php';

if (isset($_GET['id'])) {
  $id = (int) $_GET['id']; // cast untuk keamanan
  $result = mysqli_query($conn, "SELECT * FROM portofolio WHERE id = $id");

  if ($data = mysqli_fetch_assoc($result)) {
    $file_path = '../halaman/assets/img/portofolio/' . $data['gambar'];
    
    if (file_exists($file_path)) {
      unlink($file_path);
    }

    mysqli_query($conn, "DELETE FROM portofolio WHERE id = $id");
  }
}

header("Location: section_galeri.php?deleted=1");
exit;