<?php

// For proper mime-type detection php-pecl-Fileinfo package should be installed on *nix systems
function DetectMimeType($FileName)
{
  $FileInfo = new finfo(FILEINFO_MIME, '/usr/share/misc/magic');
  $Result = $FileInfo->file($FileName);
  //$FileInfo->close();
  return($Result);
}

chdir('../..');
include('global.php');
$DbResult = $Database->select('SystemFile', '*', 'Id='.addslashes($_GET['Id']));
if($DbResult->num_rows > 0)
{
  $DbRow = $DbResult->fetch_assoc();
  Header('Content-Type: '.DetectMimeType($DbRow['Name']));
  Header('Content-Disposition: attachment; filename="'.$DbRow['Name'].'"');
  echo(file_get_contents($Config['UploadFileFolder'].'/'.$DbRow['Id']));
} else echo('Soubor nenalezen!');

?>