The download helper

The download helper only has one function, but it complements the file helper very nicely. You might create a file on a website and then want to serve it up to the reader as a text file, rather than converting it to a web page. A good example would be a database backup file, like the one we just created for our application.

In order to code this over an internet connection, you must specify the type of page you want in the HTTP headers. CI's download helper does this for you in the background. Load the helper with:

$this->load->helper('download');

Its single method is used like this:

force_download($name, $data);

Where $name is the name you give to the downloaded file, and $data represents the file contents. If you want to download ...

Get CodeIgniter 1.7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.