query($sql); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $row['medical_doc_name'] . '"'); ob_clean(); echo $row['medical_doc']; exit; } else { echo "Document not found"; } }