通过调整大小的多个图像上传在codeigniter中不起作用

时间:2013-04-17 19:46:26

标签: image codeigniter for-loop resize uploading

我正在尝试使用codeigniter框架中的缩略图上传和调整图像大小。问题是上传和调整图像大小时我在表单上传单个图像时工作正常。当我上传两个或更多图像时,图像将上传为原始大小和缩略图正在调整大小与正确的尺寸。我希望原始图像重新调整大小为960 * 360和50 * 50的上传图像的缩略图。这是我的控制器。任何帮助这个问题非常感谢。谢谢。

function manage_image(){
    $data['image'] = $this->Flash_model->select_image();
        if($this->input->post('Submit')){
           for($i=1;$i<=6;$i++)
            {   
               if($_FILES['photo_'.$i]['name']!=''){
                   //upload thumbnail
                    $config = array();
                    $config['upload_path'] = 'flashimages/';
                    $config['allowed_types'] = 'png|jpg|jpeg';
                    $config['file_name'] = '0'.$i;
                    $config['max_size'] = '1024';
                    $config['overwrite'] = 'TRUE';  
                    $this->load->library('upload');
                    $this->upload->initialize($config); 
                    if ( ! $this->upload->do_upload('photo_'.$i))
                    {
                        $data['alert'] = $this->upload->display_errors();                       
                        $this->load->view('admin/homepage/add_image', $data);
                    }   
                    else
                    {
                        $upload_data = $this->upload->data();

                        $filename = $upload_data['file_name'];

                        $width = $upload_data['image_width'];
                        $height = $upload_data['image_height'];
                        $config1 = array();
                        $this->load->library('image_lib');
                        $config1['source_image'] = 'flashimages/'.$filename;

                        if($width>960 ||$height>360 ){
                            //resize image
                            $sizes = array('width' => $width, 'height' => $height, 'new_width' => 960, 'new_height' => 360);
                            $newsize = array();
                            //$newsize = $this->image_lib->size_calculator($sizes);
                            $config1['maintain_ratio'] = FALSE;
                            $config1['width'] = $sizes['new_width'];
                            $config1['height'] = $sizes['new_height'];
                            $this->image_lib->initialize($config1);
                            $this->image_lib->resize();
                            $this->image_lib->clear();
                        }
                        $config1['maintain_ratio'] = FALSE;
                        $config1['width'] = 120;
                        $config1['height'] = 50;
                        $config1['create_thumb'] = TRUE;
                        $config1['thumb_marker'] = 'thumb_';
                        $this->image_lib->initialize($config1);
                        $this->image_lib->resize();
                        $this->Flash_model->save_image('photo_'.$i,$filename);
                        $data['alert'] = 'image uploaded';
                    }
                }
            }
            $data['image'] = $this->Flash_model->select_image();
            $this->load->view('admin/homepage/add_image',$data);
        }else{
            $this->load->view('admin/homepage/add_image',$data);
        }   
    }

0 个答案:

没有答案