dwh/open_file.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2023-10-02 10:26:17 +00:00
<?php
$PARENT_SCRIPTNAME='rep_financial.php';
//include_once 'init/initialisation_parameter.php';
if ( ! function_exists ( 'mime_content_type ' ) ) {
function mime_content_type ( $f ) {
return trim ( exec ('file -bi ' . escapeshellarg ( $f ) ) ) ;
}
}
ob_start();
include_once 'script_auth.php';
start_serving_file();
ob_end_flush();
function start_serving_file() {
$tahun = substr($_REQUEST['TGL_POS'], 6,4);
$bulan = substr($_REQUEST['TGL_POS'], 3,2);
$tanggal = substr($_REQUEST['TGL_POS'], 0,2);
$tglfile = $tahun.$bulan.$tanggal;
$real_path = "{$_SERVER['DOCUMENT_ROOT']}/Data";
//$real_path = LH_FOLDER;
//$web_path = LH_FOLDER;
$request_filename = "LH_$tglfile.pdf";
$request_file = "$real_path/$request_filename";
//echo $request_file;
if (file_exists($request_file)) {
$serve_filename = "$request_filename";
$data = file_get_contents($request_file);
if (!is_null($data)) {
$type = mime_content_type($request_file);
$size = filesize($request_file);
header ("Content-type: $type");
header ("Content-length: {$size}");
//header ("Content-Disposition: attachment; filename=$serve_filename");
header ("Content-Description: PHP Generated Data");
echo $data;
} else {
die("Unable to open the file. Please contact the webmaster.");
}
} else {
die ("The request file '{$request_filename}' not found.");
}
}
?>