简体   繁体   中英

create thumbnail only one time when uploading several images CodeIgniter

This is the code:

for ($i=0; $i<$total_count_of_files; $i++)
                {
                    $_FILES['userfile']['name'] = $_FILES['pics']['name'][$i];
                    $_FILES['userfile']['type'] = $_FILES['pics']['type'][$i];
                    $_FILES['userfile']['tmp_name'] = $_FILES['pics']['tmp_name'][$i];
                    $_FILES['userfile']['error'] = $_FILES['pics']['error'][$i];
                    $_FILES['userfile']['size'] = $_FILES['pics']['size'][$i];

                    $config['upload_path'] = './uploads/gallery/';
                    $config['allowed_types'] = 'jpg|jpeg|gif|png';
                    $config['max_size'] = '0';
                    $config['encrypt_name'] = TRUE;

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

                    if($this->upload->do_upload())
                    {
                        $pic = $this->upload->data();

                        // Thumbnail
                        $config1['image_library'] = 'gd2';
                        $config1['source_image'] = $pic['full_path'];
                        $config1['create_thumb'] = TRUE;
                        $config1['maintain_ratio'] = FALSE;
                        $config1['width'] = 180;
                        $config1['height'] = 113;

                        $this->load->library('image_lib', $config1);
                        $this->image_lib->resize();
                        // Thumbnail ends

                        $count_imgs += 1;
                        $this->galleries_model->add_image($pic['file_name'], $pic['image_width'], $pic['image_height'], $gallery_id);
                    }
                }

The code works fine, just one problem with the thumbnail creation, it makes only one thumb (the first image which is uploaded) and then not create (but continue to upload the other original images fine). what could be the problem?

Thank you.

i think you must be clear image library class after each image creation.

$this->image_lib->resize();
$this->image_lib->clear();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM