[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
repository_afbs
/
user
/
[
Home
]
File: download.php
<?php session_start(); require_once 'config/database.php'; // Check if user is logged in if (!isset($_SESSION['user_id'])) { header("Location: login.php"); exit(); } $database = new Database(); $db = $database->getConnection(); $id = isset($_GET['id']) ? $_GET['id'] : 0; // Get file path $query = "SELECT pdf_file, title FROM theses WHERE id = :id AND status = 'approved'"; $stmt = $db->prepare($query); $stmt->bindParam(':id', $id); $stmt->execute(); $thesis = $stmt->fetch(PDO::FETCH_ASSOC); if ($thesis) { // Update download count $update_query = "UPDATE theses SET downloads = downloads + 1 WHERE id = :id"; $update_stmt = $db->prepare($update_query); $update_stmt->bindParam(':id', $id); $update_stmt->execute(); // Log download $log_query = "INSERT INTO downloads_log (thesis_id, user_id, ip_address) VALUES (:thesis_id, :user_id, :ip_address)"; $log_stmt = $db->prepare($log_query); $log_stmt->bindParam(':thesis_id', $id); $log_stmt->bindParam(':user_id', $_SESSION['user_id']); $log_stmt->bindParam(':ip_address', $_SERVER['REMOTE_ADDR']); $log_stmt->execute(); $file_path = "uploads/theses/" . $thesis['pdf_file']; if (file_exists($file_path)) { header('Content-Description: File Transfer'); header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . basename($thesis['title'] . '.pdf")'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file_path)); readfile($file_path); exit; } } header("Location: index.php"); exit(); ?>