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);

  }
2
  • stackoverflow.com/questions/40778683/… Commented Oct 28, 2019 at 13:52
  • @NiallLonergan i have join table inside my table.. its not working when im try it Commented Oct 28, 2019 at 14:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.