&1"; $out = shell_exec($cmd); if (!$out) { $out = ""; } // Ambil nomor resi: prioritas CODE-128, fallback QR-Code $resi = null; $lines = preg_split("/\r\n|\n|\r/", trim($out)); foreach ($lines as $line) { if (preg_match('/^CODE-128:(.+)$/', trim($line), $m)) { $resi = trim($m[1]); break; } } if ($resi === null) { foreach ($lines as $line) { if (preg_match('/^QR-Code:(.+)$/', trim($line), $m)) { $resi = trim($m[1]); break; } } } if ($resi === null || $resi === "") { // kalau gak kebaca, tetap simpan log gagal biar ada bukti foto $status = "gagal"; $pesan = "Barcode tidak terbaca."; } else { // 4) Cek resi valid di tabel resi (sesuaikan kalau nama tabel/kolom kamu beda) $status = "gagal"; $pesan = "Resi tidak terdaftar."; $stmt = $conn->prepare("SELECT 1 FROM resi WHERE nomor_resi = ? LIMIT 1"); $stmt->bind_param("s", $resi); $stmt->execute(); $r = $stmt->get_result(); if ($r && $r->num_rows > 0) { $status = "berhasil"; $pesan = "Resi valid, akses dibuka."; } } // 5) Simpan ke tabel yang DIPAKAI log.php: log_akses // log.php kamu pakai kolom: created_at, nomor_resi, status, pesan, foto_path $fotoPathUrl = "/smart-drop-point/uploads/" . $filename; $stmt2 = $conn->prepare("INSERT INTO log_akses (nomor_resi, status, pesan, foto_path, created_at) VALUES (?, ?, ?, ?, NOW())"); $stmt2->bind_param("ssss", $resi, $status, $pesan, $fotoPathUrl); $stmt2->execute(); // 6) Balik ke halaman log (biar gak kepisah) header("Location: /smart-drop-point/public/log.php"); exit;