<?php
if(count(get_included_files()) ==1) exit("Direct access not permitted.");
require_once('include/global.php');
if (!isset($_SESSION)) session_start();
$db=pDatabase::getInstance();
error_log($dest_module);
if(!$db->ceckmodule($dest_module)) exit;

if(isset($_GET['id'])){
	$query="SELECT *
			FROM tb_dokumen as t1
			WHERE t1.id=? ";
	$rs=$db->loadAssoc($query,array($_GET['id']));
	if(isset($rs['folder'])){
		$tipe=strtolower($rs['tipefile']);
		$namaawal=$rs['nama_awal'];
		$filed=$rs['folder']."/".$rs['nama_baru'];
		if($tipe=="pdf"){
			header('Content-type: application/pdf');
			header('Content-Disposition: inline; filename="'.$namaawal.'"');
			header('Content-Transfer-Encoding: binary');
			header('Content-Length: ' . filesize($filed));
			header('Accept-Ranges: bytes');
		}else if($tipe=="png" || $tipe=="jpg" || $tipe=="jpeg" || $tipe=="bmp"){
			header('Content-type: image');
			header('Content-Disposition: inline; filename="'.$namaawal.'"');
			header('Content-Transfer-Encoding: binary');
			header('Content-Length: ' . filesize($filed));
			header('Accept-Ranges: bytes');
		}else{
			header('Content-type: application/zip');
			header('Content-Disposition: inline; filename="'.$namaawal.'"');
			header('Content-Transfer-Encoding: binary');
			header('Content-Length: ' . filesize($filed));
			header('Accept-Ranges: bytes');
		}
		
		@readfile($filed);
	}
}

?>