CodeIgniter Forums
Multiple images and data upload - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: Multiple images and data upload (/showthread.php?tid=64520)

Multiple images and data upload - azharsaleem6 - 02-29-2016

i'm beginner in codeigniter i want to upload multiple images and data upload and save images name in database. i don't understand how to store multiple files name in database. And upload images in my root folder.

Here is my code


<form method="post" enctype="multipart/form-data" action="<?=base_url();?>vendors/home/do_upload">
                    <input type="text" name="product_name" class="form-control" required>

                    <input type="text" name="product_price" class="form-control" required>

                    <input type="text" name="old_price" class="form-control" required>

                    <input type="file" name="image1" required>

                    <input type="file" name="image2" required>

                    <input type="file" name="image3" required>

                    <input type="file" name="image4" required>



public function do_upload()

if ($_POST) {

$config['upload_path'] = './uploads/';
$config['max_size'] = 90000;
$config['max_width'] = 50000;
$config['max_height'] = 50000;
$config['allowed_types'] = 'jpg|png|gif|jpeg';


if (!$this->upload->do_upload()) {

$error = array('error' => $this->upload->display_errors());



$query = $this->upload->data();

$data = array(
          'pro_name' => $_POST['product_name'],
           'prod_price' => $_POST['product_price'], 
           'old_price' => $_POST['old_price'],  
            'prod_image1' => [' '],
            'prod_image2' => [' '],
            'prod_image3' => [' '],
            'prod_image4' => [' '],



public function add_product($data)


RE: Multiple images and data upload - Wouter60 - 02-29-2016

You need an extra library. Here is an excellent one:

RE: Multiple images and data upload - azharsaleem6 - 02-29-2016

Thansk Wouter60
But how i save multiple images name in my database ?

RE: Multiple images and data upload - Mangetsu - 03-01-2016

If you have fixed number of images just have one column in table for each. If you may have variable number of images, or want to save additional data for each image (extension, size etc) you may think about having images table connected to products by product_id key.

RE: Multiple images and data upload - Wouter60 - 03-01-2016

After uploading the files with the library, you can call $this->upload->data();
If you do this:
PHP Code:
$uploaded $this->upload->data(); 
then you have an array containing the metadata of all your uploaded files.

Now, let's assume you have a table in your database, called "uploads" with the fields: id, file_name, file_path, file_size, is_image, image_width, image_height. To store the data of each file as a record in your table, do this:

PHP Code:
foreach ($uploaded as $file) {
 $data = array(
   'file_name' => $file['file_name'],
   'file_path' => $file['file_path'],
   'file_size' => $file['file_size'],
   'is_image' => $file['is_image'],
   'image_width' => $file['image_width'],
   'image_height' => $file['image_height']

For a complete list of all file attributes that are in $this->upload->data(), check this page: