使用codeigniter将多个图像上载到数据库

My functions upload only one image at a time, when the form is submitted. I can not upload multiple images at once. This is a huge problem because I am building a car-sales website, and people need to upload multiple car images.

My upload.php controller:

<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('upload_model');

}
function index()
{
$this->load->view('common/header');
$this->load->view('nav/top_nav');
$this->load->view('upload_form', array('error' => ' ' ));

}

  function do_upload()
{
if($this->input->post('upload'))
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '1024';
$config['max_width']  = '1024';
$config['max_height']  = '768';
 $this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{

$data=$this->upload->data();
$this->thumb($data);
$file=array(

'img_name'=>$data['raw_name'],
'thumb_name'=>$data['raw_name'].'_thumb',
'ext'=>$data['file_ext'],
'upload_date'=>time()
);
$this->upload_model->add_image($file);
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
} 
else
{
 redirect(site_url('upload'));
}
}   

 function thumb($data)
{
$config['image_library'] = 'gd2';
$config['source_image'] =$data['full_path'];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 160;
$config['height'] = 110;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
}

My upload_form.php view:

   <?php $attributes = array('name' => 'myform');
 echo form_open_multipart('/upload/do_upload',$attributes);?>

  <input type="file" name="userfile" size="20" />

  <input type="submit" value="upload" name="upload" />

  <?php echo form_close(); ?>

My upload_model.php Model:

  <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Upload_model extends CI_Model {
  public function __construct()
 {
 parent::__construct();
 }
 function add_image($data)
 {

 $this->db->insert('jobs',$data);
 }
 }

I can't modify the function in a way that allows multiple image upload. I would highly appreciate any kind of guidance or help. Thank you in advance!

   #####################
    # Uploading multiple# 
    #     Images        #
    #####################


    $files = $_FILES;
    $count = count($_FILES['uploadfile']['name']);
    for($i=0; $i<$count; $i++)
            {
            $_FILES['uploadfile']['name']= $files['uploadfile']['name'][$i];
            $_FILES['uploadfile']['type']= $files['uploadfile']['type'][$i];
            $_FILES['uploadfile']['tmp_name']= $files['uploadfile']['tmp_name'][$i];
            $_FILES['uploadfile']['error']= $files['uploadfile']['error'][$i];
            $_FILES['uploadfile']['size']= $files['uploadfile']['size'][$i];
            $this->upload->initialize($this->set_upload_options());//function defination below
            $this->upload->do_upload('uploadfile');
            $upload_data = $this->upload->data();
            $name_array[] = $upload_data['file_name'];
            $fileName = $upload_data['file_name'];
            $images[] = $fileName;

            }
          $fileName = $images;

what's happening in code??

well $_FILE---->it is an associative array of items uploaded to the current script via the POST method.for further look this LINK

it's an automatic variable avaliable within all scopes of script

function set_upload_options()
  { 
  // upload an image options
         $config = array();
         $config['upload_path'] = LARGEPATH; //give the path to upload the image in folder
         $config['remove_spaces']=TRUE;
         $config['encrypt_name'] = TRUE; // for encrypting the name
         $config['allowed_types'] = 'gif|jpg|png';
         $config['max_size'] = '78000';
         $config['overwrite'] = FALSE;
         return $config;
  }

and in your html markup don't don't forget:

Input name must be be defined as an array i.e. name="file[]"

Input element must have multiple="multiple" or just multiple

3.$this->load->library('upload'); //to load library

4.The callback, $this->upload->do_upload() will upload the file selected in the given field name to the destination folder.

5.And the callback $this->upload->data() returns an array of data related to the uploaded file like the file name, path, size etc.