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 an existing file, you have to read it into a string first:
function backup_download($file = '', $ext = '') { $this->load->helper('file'); $this->load->helper('download'); $data = read_file("backups/".$file.".".$ext); force_download...