prepare( 'SELECT i.filename, b.user_id FROM bug_report_images i JOIN bug_reports b ON b.id = i.bug_id WHERE i.id = ?' ); $stmt->execute([(int) ($_GET['id'] ?? 0)]); $image = $stmt->fetch(); $me = current_user(); if (!$image || ((int) $image['user_id'] !== (int) $me['id'] && !user_has_permission('bugs.manage'))) { show_not_found(); } $path = BUG_UPLOAD_DIR . $image['filename']; $types = ['png' => 'image/png', 'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'webp' => 'image/webp']; $type = $types[strtolower(pathinfo((string) $image['filename'], PATHINFO_EXTENSION))] ?? null; if (strpos((string) $image['filename'], '/') !== false || $type === null || !is_file($path)) { show_not_found(); } session_write_close(); header('Content-Type: ' . $type); header('Content-Length: ' . filesize($path)); header('Cache-Control: private, max-age=86400'); header('X-Content-Type-Options: nosniff'); readfile($path);