0

I have already generated a code that will upload multiple images in codeigniter, however I can't generate a large size of the uploaded images to other directory using codeigniter image library.

Using the codes below, it will only generate one image even though if the user uploaded multiple images.

  function insert_prod(){   

    $foldername = $_POST['folder'];
    $path = './uploads/products/'.$foldername;

    mkdir($path, 0777, true);
    mkdir($path.'/zoomimages', 0777, true);

    $config = array();
    $config['upload_path'] = $path;
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']      = '0';
    $config['overwrite']     = FALSE;

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

    $files = $_FILES;
    $cpt = count($_FILES['userfile']['name']);
    for($i=0; $i<$cpt; $i++){

        $_FILES['userfile']['name']= $files['userfile']['name'][$i];
        $_FILES['userfile']['type']= $files['userfile']['type'][$i];
        $_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
        $_FILES['userfile']['error']= $files['userfile']['error'][$i];
        $_FILES['userfile']['size']= $files['userfile']['size'][$i];    

        $config['file_name'] = 'img_'.$i;

        $this->upload->initialize($config);
        $this->upload->do_upload();

        $upload_data = array('upload_data' => $this->upload->data());
        $full_path = $upload_data['upload_data']['full_path'];
        $u_data = $upload_data['upload_data'];
        // var_dump( $this->upload->data());
        // var_dump($upload_data); 
        echo $cpt;
        $config1['image_library'] = 'gd2';
        $config1['source_image']    = $full_path;
        $config1['new_image'] =$path.'/zoomimages';
        $config1['create_thumb'] = FALSE;
        $config1['maintain_ratio'] = TRUE;
        $config1['width']    = 300;
        $config1['height']  = 300;

        $this->load->library('image_lib', $config1); 
        $this->image_lib->resize();
        $this->image_lib->clear();
    }
}
Adarsh M Pallickal
  • 813
  • 3
  • 16
  • 37

1 Answers1

0

You are loading library with $this->load->library('image_lib', $config1); inside your loop so codeigniter see the class is already load so its not setting your $config1 again

Move $this->load->library('image_lib'); out side your loop

Then add $this->image_lib->initialize($config1); instant of $this->load->library('image_lib', $config1);

Minhaz
  • 446
  • 5
  • 7