Wednesday, May 24, 2017

Image resize when uploading Codeingniter 3

Image resize when uploading Codeingniter 3

We must enable file upload and fileinfo extensions.

 if(!empty($_FILES['image']['name'])){  
         $config['upload_path'] = './uploads/onlineadmission/';  
                     $config['allowed_types'] = 'gif|jpg|png';  
                     $config['max_size']   = '1500';  
                     $config['encrypt_name'] = TRUE;  
         $this->load->library('upload', $config);  
           if (!$this->upload->do_upload('image')){  
               $filerror = array('filerror' => $this->upload->display_errors('',''));  
               $this->data['filerror'] = $filerror;   
               $picture = '';             
           }  
           else{  
               $data_upload =$this->upload->data();  
               $picture = $data_upload['file_name'];  
                                    $configer = array(  
                                     'image_library'  => 'gd2',  
                                     'source_image'  => $data_upload['full_path'],  
                                     'maintain_ratio' => TRUE,  
                                     'width'      => 200,  
                                     'height'     => 200,  
                                    );  
                                    $this->image_lib->clear();  
                                    $this->image_lib->initialize($configer);  
                                    $this->image_lib->resize();  
           }  
       }else{  
         $picture = '';  
       }    

No comments:

Post a Comment

Total Pageviews