🔥 CodeIgniter Intermediate

What is CI4 response download?

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.