<?php
/**
 * Author - koder_alex
 * ISQ - 669906617
 * VK - https://vk.com/koder_alex
 * It is forbidden to give, sell, modify.
 */
defined('ACCESS') OR die('No direct script access...');
if (!(isset($_GET['folder']) && is_dir(FILES_PATH . 'mail/files/' . $_GET['folder']) && isset($_GET['hash']) && is_file(FILES_PATH . 'mail/files/' . $_GET['folder'] . '/' . $_GET['hash'])))
    redirect('/mail/', 'Ошибка доступа.', 'error');
$file = DB::$pdo->queryFetch("SELECT name, extension, type, size FROM mail_files_vk WHERE `folder` = '" . $_GET['folder'] . "' AND `tmp_name` = '" . $_GET['hash'] . "' LIMIT 1");
if (ini_get('zlib.output_compression'))
    ini_set('zlib.output_compression', 'Off');

header('Accept-Ranges: bytes');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: " . $file['type']);
if (preg_match('#^image/#i', $file['type']))
    header('Content-Disposition: filename="' . $file['name'] . '.' . $file['extension'] . '";');
else
    header('Content-Disposition: attachment; filename="' . $file['name'] . '.' . $file['extension'] . '";');
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $file['size']);
ob_clean();
flush();
readfile(FILES_PATH . 'mail/files/' . $_GET['folder'] . '/' . $_GET['hash']);
clearstatcache();
exit();
?>
