|
|
|
<?php
|
|
|
|
|
|
|
|
include('config.inc.php');
|
|
|
|
|
|
|
|
$db = new PDO('mysql:host=' . $config['host'] . ';dbname=' . $config['database'], $config['dbuser'], $config['password'], [
|
|
|
|
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
|
|
|
|
\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8mb4'"
|
|
|
|
]);
|
|
|
|
|
|
|
|
$fileId = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
|
|
|
if ($fileId === 0)
|
|
|
|
{
|
|
|
|
header("HTTP/1.1 404 Not Found");
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT * FROM mntn_uploads WHERE `id`=:fileId";
|
|
|
|
$stmt = $db->prepare($sql);
|
|
|
|
|
|
|
|
if (!$stmt->execute(array('fileId' => $fileId)))
|
|
|
|
{
|
|
|
|
error_log(print_r($stmt->errorInfo(), true));
|
|
|
|
header("HTTP/1.1 404 Not Found");
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
$row = $stmt->fetch();
|
|
|
|
if (!$row)
|
|
|
|
{
|
|
|
|
header("HTTP/1.1 404 Not Found");
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
$dest = $config['term_logs_root'] . $row['path'];
|
|
|
|
if (!file_exists($dest))
|
|
|
|
{
|
|
|
|
header("HTTP/1.1 404 Not Found");
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
$parts = pathinfo($row['file_name']);
|
|
|
|
$fileName = $parts['filename'] . '_' . str_replace(array('-', ' ', ':'), '', $row['create_time']) . '.' . $parts['extension'];
|
|
|
|
|
|
|
|
Header("Content-type: application/octet-stream");
|
|
|
|
Header("Accept-Ranges: bytes");
|
|
|
|
Header("Accept-Length: " . $row['file_size']);
|
|
|
|
Header("Content-Disposition: attachment; filename=" . $fileName);
|
|
|
|
|
|
|
|
readfile($dest);
|
|
|
|
exit();
|