/home1/kilifi/public_html
Edit: /home1/kilifi/public_html/download.php (1792B)
prepare("SELECT file_path FROM documents WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
if ($doc = $result->fetch_assoc()) {
$file_path = 'uploads/docs/' . $doc['file_path'];
if (file_exists($file_path)) {
$mode = isset($_GET['mode']) ? $_GET['mode'] : 'download';
// Increment download count in documents table
mysqli_query($con, "UPDATE documents SET downloads = downloads + 1 WHERE id = $id");
// Log download
$ip = $_SERVER['REMOTE_ADDR'];
$stmt_log = $con->prepare("INSERT INTO downloads_log (document_id, ip_address) VALUES (?, ?)");
$stmt_log->bind_param("is", $id, $ip);
$stmt_log->execute();
$stmt_log->close();
// Get file info
$mime_type = mime_content_type($file_path);
$file_name = basename($file_path);
// Set headers
header('Content-Type: ' . $mime_type);
if ($mode == 'view') {
header('Content-Disposition: inline; filename="' . $file_name . '"');
} else {
header('Content-Disposition: attachment; filename="' . $file_name . '"');
}
header('Content-Length: ' . filesize($file_path));
header('Pragma: no-cache');
header('Expires: 0');
// Read file
readfile($file_path);
exit;
}
}
}
// If error or file not found
header('Location: documents.php');
exit;
?>