I have a form with the possibility to upload 3 images. In codeigniter I made a foreach loop that will process the images, and save them to my database. That works great.

But I need to resize the images. When I upload one image, the resizing works but with more then 1 image, the first image will look like shit and the second and third image will not be resized... Can you guys help me out?

$this->load->library('upload');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['encrypt_name'] = TRUE;
//$config['overwrite'] = TRUE;

$this->upload->initialize($config);
 $count = 0;
            foreach($_FILES as $field => $file)
            {
                $count = $count + 1;
                // No problems with the file
                if($file['error'] == 0)
                {
                    // So lets upload
                    if ($this->upload->do_upload($field))
                    {
                        $data = $this->upload->data();

                        $data2 = array(
               'image' . $count => $data['file_name']
            );

$this->db->where('id', $query_id);
$this->db->update('ads', $data2);
//afbeeldingen verkleinen.

                    $config['image_library'] = 'gd2';
                    $config['source_image'] = $data['full_path'];
                    //$config['new_image'] = './image_uploads/';
                    $config['maintain_ratio'] = TRUE;
                    $config['width'] = 370;
                    $config['height'] = 277;
                    $this->load->library('image_lib',$config); 

                    if ( !$this->image_lib->resize()){
                $this->session->set_flashdata('errors', $this->image_lib->display_errors('', '')); 
                echo $this->image_lib->display_errors('', '');
                exit();  
              }

                    }
                    else
                    {
                        $errors = $this->upload->display_errors();
                        echo $errors;
                        exit();
                    }
                }
            }
$data['name'] = $name;
redirect('/adDetail/getDetails/' . $query_id, 'location', 200);
}
有帮助吗?

解决方案

Try Unloading image_lib at the end of your loop.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top