What is CI4 response download?
Why Interviewers Ask This
This question targets practical, hands-on experience with CodeIgniter. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.
Answer
CodeIgniter 4 provides built-in support for sending file downloads via HTTP. Download a file from disk: return $this->response->download("app/data/report.pdf") — CI4 sets the correct Content-Disposition: attachment header and streams the file. The first argument can be the file path, second can be the filename to display: $this->response->download("/path/to/file", "my_report.pdf"). Download from string/binary data: $data = $pdfGenerator->generate(); return $this->response->download("report.pdf", $data, true) — the third argument (true) indicates in-memory content. For inline display (open in browser instead of download): $this->response->setContentType("application/pdf")->noCache()->setBody($data). Large file downloads: use PHP's readfile() or CI4's download with chunked output to avoid memory exhaustion.
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex CodeIgniter answers easy to follow.
Previous
What is CI4 controller method injection?
Next
What is CodeIgniter 4 CLI application development?