39331-vm/archive_download.php
Flatlogic Bot 522a55296c arsip_demo
2026-03-26 11:04:24 +00:00

27 lines
787 B
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/archive_bootstrap.php';
ensure_archive_table();
$user = require_login();
$id = (int) ($_GET['id'] ?? 0);
$record = fetch_record_by_id($id);
if (!$record || !can_view_record($user, $record) || empty($record['attachment_path'])) {
http_response_code(404);
exit('Lampiran tidak ditemukan.');
}
$file = __DIR__ . '/' . $record['attachment_path'];
if (!is_file($file)) {
http_response_code(404);
exit('File tidak tersedia di server.');
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . rawurlencode((string) $record['attachment_name']) . '"');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;