You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB
PHTML

2 years ago
<?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;
}
2 years ago
$parts = pathinfo($row['file_name']);
$fileName = $parts['filename'] . '_' . str_replace(array('-', ' ', ':'), '', $row['create_time']) . '.' . $parts['extension'];
2 years ago
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . $row['file_size']);
2 years ago
Header("Content-Disposition: attachment; filename=" . $fileName);
2 years ago
readfile($dest);
exit();