0

I have a problem with multiple image upload in codeigniter. I want to insert to each field in database.

I've tried to upload single a file but when I change to multiple upload, it's not working.

This is my controller to add the whole data from upload images:

public function addprod(){
        $item->gambar_produk = null;
        $item->thumb_produk1 = null;


        $data = array(
                    'page' => 'addprod',
                    'row' => $item

        );
        $data['title'] = 'Form Add';

        $this->load->view('admin/addprod', $data);          


}

This is My Controller to add images and this is my first images controller:

        $config['upload_path'] = './assets/upload/images/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size']  = '2400';
        $config['max_width']  = '2024';
        $config['max_height']  = '2024';

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

                if ($this->upload->do_upload('image')){

                    $post['image'] = $this->upload->data('file_name');
                    $this->Model_product->add($post);                
                        redirect('Product/viewprod');
                } else {
                    $error = $this->upload->display_errors();
                    $this->session->flashdata('error', $error);
                    redirect('Product/addprod');
                }

and this is my second images:

        $config2['upload_path'] = './assets/upload/images/';
        $config2['allowed_types'] = 'gif|jpg|png|jpeg';
        $config2['max_size']  = '2400';
        $config2['max_width']  = '2024';
        $config2['max_height']  = '2024';

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


                if ($this->upload->do_upload('image2')){

                    $post['image2'] = $this->upload->data('file_name');
                    $this->Model_product->add($post);                

                        redirect('Product/viewprod');

                } else {

                    redirect('Product/addprod');
                }

this is my model:

public function add($post){
  $data = [

                 'image' => $post['image'],
                'image2' => $post['image2']                

   ];

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

  }
Lucas Meine
  • 1,524
  • 4
  • 23
  • 32
Gdunk
  • 1
  • 2

0 Answers0