<?php
$id = $output[1];
$db->join(TABLE_CAT . ' c', 'f.cid=c.id', "INNER");
if ($isLogged) {
    $db->where('(f.approved_at IS NOT NULL OR f.user_id="' . $AuthUser['id'] . '")');
} else {
    $db->where('f.approved_at', NULL, 'IS NOT');
}
$file = $db->where('f.status',1)->where('f.deleted_at',NULL,'IS')->where('f.id',$id)->getOne(TABLE_FILES.' f','f.name,f.id,f.dname,f.ext,c.folder');
if(!$file){
    if (ERROR_PAGE == true) {
        require __DIR__ . '/ErrorPage.php';
    } else {
        Redirect(APP_URL);
    }
}
$extension = pathinfo($file['dname'],PATHINFO_EXTENSION);
if(!in_array($extension,$allowExt)){
    $extension  = '';
}
$filename = $extension?$file['dname']:$file['dname'].'.'.$file['ext'];
$Path = $RootPath.'/'.$file['folder'].$filename;
$dfilename = $file['name'].'.'.pathinfo($Path,PATHINFO_EXTENSION);
if(file_exists($Path)){
$db->where('id',$id)->update(TABLE_FILES,['dl_today'=>$db->inc(1),'download'=>$db->inc(1)]);
fileDownload($Path,$dfilename,strtoupper($file['ext']));
} else {
    if (ERROR_PAGE == true) {
        require __DIR__ . '/ErrorPage.php';
    } else {
        Redirect(APP_URL);
    }
}
 