Uploading files with CodeIgniter

CodeIgniter comes with very good file uploading support, which can take a lot of the hassle out of writing upload functions.

Getting ready

There are some settings you should be aware of which you'll probably need to change for your environment. Firstly, ensure that you load the upload library using:

$this->load->library('upload'); 

The following is a table of settings that should be placed in the $config array in the controller you are using, such as the following Fileupload controller:

Setting

Default

Change to

Description

upload_path

None

None

It specifies the path to the folder where the uploaded file should go. Ensure that you have set the correct permissions to enable CodeIgniter to write to it.

Get CodeIgniter 2 Cookbook 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.