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."; } ?>