db_archive/download.php
2024-07-18 17:31:32 -07:00

45 lines
1.4 KiB
PHP

<?php
include 'config.php';
if (isset($_GET['file'])) {
$file = $_GET['file'];
// Get file details from the database
$stmt = $main_db->prepare("SELECT * FROM archive_logs WHERE archive = ?");
$stmt->bind_param("s", $file);
$stmt->execute();
$result = $stmt->get_result();
$fileDetails = $result->fetch_assoc();
$stmt->close();
if ($fileDetails) {
$filePath = 'uploads/' . $file;
if (file_exists($filePath)) {
// Increment download count
$stmt = $main_db->prepare("UPDATE archive_logs SET downloads = downloads + 1 WHERE archive = ?");
$stmt->bind_param("s", $file);
$stmt->execute();
$stmt->close();
// Serve the file for download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($filePath).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filePath));
readfile($filePath);
exit;
} else {
echo "File not found.";
}
} else {
echo "Invalid file.";
}
} else {
echo "No file specified.";
}
?>