<?php  session_start(); error_reporting(0);  
require_once("../j_conn/url.php");
require_once("../j_conn/dbc.php");
require_once("../j_incs/functions.php");
if(!isset($_SESSION['j_admin']) && !isset($_SESSION['j_admin'])){ die("Error"); }
$ref = ($_GET['r']); $ref = RMC($ref); 
if(isset($_SESSION['j_admin'])){
$sql4="SELECT * from j_pays WHERE j_user_id='".$id."' AND j_transact_id='".$ref."' AND j_deleted < 1 order by j_id desc limit 1"; //check 
}else{
$sql4="SELECT * from j_pays WHERE j_deleted < 1 AND j_transact_id='".$ref."' order by j_id desc limit 1"; //check 
}
$result4 = runSQL($sql4);
$count = mysqli_num_rows($result4);
$data4 = mysqli_fetch_array($result4);
$file = $data4['j_proof'];
if(empty($file)){
die("<div class='alert alert-danger'> No file found.</div>");
}
if($count > 0){ }else{
die("<div class='alert alert-danger'> No Access.</div>");
}
$ext = substr($file, strrpos($file, '.') + 1);	
$file = "../j_files/j_img/payments/$file";
$timex = time();
$rename = "Proof-of-payment-$ref-$timex.$ext";
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.($rename).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
}
?>