CodeIgniter File Uploading


CodeIgniter provides a built-in file uploading library that makes it easy to handle file uploads in your application.

To use the file uploading library, you will first need to load it in your controller:


Then, you can use the do_upload() method to handle the file upload. This method takes the name of the file input field as a parameter and returns an array of data about the uploaded file.

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';


if ( ! $this->upload->do_upload('my_file'))
  $error = array('error' => $this->upload->display_errors());
  $this->load->view('upload_form', $error);
  $data = array('upload_data' => $this->upload->data());
  $this->load->view('upload_success', $data);

The $config array contains various options for the file upload, such as the upload path and allowed file types.

If the file upload is successful, the do_upload() method will return an array of data about the uploaded file, including the file name, file size, and file type. If the file upload fails, it will return an error message.

You can also use the do_multi_upload() method to handle multiple file uploads at once.

For more information on file uploading in CodeIgniter, you can check out the official documentation: