| Server IP : 104.21.73.108 / Your IP : 216.73.216.59 Web Server : Apache/2 System : Linux cat167-197.static.lnwhostname.com 5.10.0-20-amd64 #1 SMP Debian 5.10.158-2 (2022-12-13) x86_64 User : paphayomho ( 1042) PHP Version : 5.6.40 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/paphayomho/domains/paphayomhospital.go.th/public_html/procurement/ |
Upload File : |
<?php
include 'config.php';
// ตรวจสอบ Login
if (!isset($_SESSION['admin_login'])) { header("Location: login.php"); exit; }
if (isset($_GET['id'])) {
$id = intval($_GET['id']);
// 1. ดึงชื่อไฟล์ออกมาเพื่อลบออกจากโฟลเดอร์
$stmt = $conn->prepare("SELECT file_path FROM posts WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$data = $result->fetch_assoc();
if ($data && !empty($data['file_path'])) {
$file_to_delete = "uploads/" . $data['file_path'];
if (file_exists($file_to_delete)) {
@unlink($file_to_delete); // ลบไฟล์จริง
}
}
// 2. ลบข้อมูลในฐานข้อมูล
$del_stmt = $conn->prepare("DELETE FROM posts WHERE id = ?");
$del_stmt->bind_param("i", $id);
if ($del_stmt->execute()) {
echo "<script>alert('ลบข้อมูลเรียบร้อย'); window.location='admin.php';</script>";
}
}
?>