%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php
/**
* Handler unduh dokumen informasi publik.
* Menambah penghitung unduhan lalu mengalirkan file ke browser.
*/
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/includes/queries.php';
$id = (int) get_param('id', '0');
$dok = $id ? get_dokumen($id) : null;
if (!$dok || $dok['status'] !== 'publish' || empty($dok['file_name'])) {
http_response_code(404);
die('Dokumen tidak ditemukan.');
}
$path = UPLOAD_PATH . '/dokumen/' . basename($dok['file_name']);
if (!is_file($path)) {
http_response_code(404);
die('Berkas tidak tersedia.');
}
// Tambah penghitung unduhan.
$upd = db()->prepare('UPDATE dokumen_informasi SET downloads = downloads + 1 WHERE id = ?');
$upd->execute([$id]);
$downloadName = $dok['file_original'] ?: basename($path);
// Bersihkan output buffer sebelum mengirim file.
if (ob_get_level()) {
ob_end_clean();
}
header('Content-Description: File Transfer');
header('Content-Type: ' . ($dok['file_mime'] ?: 'application/octet-stream'));
header('Content-Disposition: attachment; filename="' . str_replace('"', '', $downloadName) . '"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
readfile($path);
exit;