Book Image

CodeIgniter 1.7

Book Image

CodeIgniter 1.7

Overview of this book

CodeIgniter (CI) is a powerful open-source PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. CodeIgniter is an MVC framework, similar in some ways to the Rails framework for Ruby, and is designed to enable, not overwhelm. This book explains how to work with CodeIgniter in a clear logical way. It is not a detailed guide to the syntax of CodeIgniter, but makes an ideal complement to the existing online CodeIgniter user guide, helping you grasp the bigger picture and bringing together many ideas to get your application development started as smoothly as possible. This book will start you from the basics, installing CodeIgniter, understanding its structure and the MVC pattern. You will also learn how to use some of the most important CodeIgniter libraries and helpers, upload it to a shared server, and take care of the most common problems. If you are new to CodeIgniter, this book will guide you from bottom to top. If you are an experienced developer or already know about CodeIgniter, here you will find ideas and code examples to compare to your own.
Table of Contents (21 chapters)
CodeIgniter 1.7
Credits
About the Authors
About the Reviewer
Preface

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 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...