Codeigniter image resize?

前端 未结 6 1428
故里飘歌
故里飘歌 2020-11-28 14:43

I have problem with image class in CI?

This is example

On controller:

$this->load->library( array(\'image_lib\') );

O

6条回答
  •  佛祖请我去吃肉
    2020-11-28 15:15

    I have tried below code. Please check.

    if (isset($_FILES['image']) && !empty($_FILES['image']['name'])) {
        $upload_path="uploads/foldername/";
        $newFileName = explode(".",$_FILES['image']['name']);
        $filename = time()."-".rand(00,99).".".end($newFileName);
        $filename_new = time()."-".rand(00,99)."_new.".end($filename);
        $config['file_name'] = $filename;
        $config['upload_path'] = $upload_path;
        $config['allowed_types'] = 'gif|jpg|png|jpeg'; 
        $this->load->library('upload', $config);
    
        if ($this->upload->do_upload('image')) 
        { 
        //Image Resizing 
        $config1['source_image'] = $this->upload->upload_path.$this->upload->file_name;
        $config1['new_image'] =  'uploads/foldername/'.$filename_new;
        $config1['maintain_ratio'] = FALSE;
        $config1['width'] = 181;
        $config1['height'] = 181; 
        $this->load->library('image_lib', $config1); 
        if ( ! $this->image_lib->resize()){ 
        $this->session->set_flashdata('message', $this->image_lib->display_errors('', ''));
    
        }
        $post_data['image'] = $filename;
        }
        else
        { 
        $this->session->set_flashdata('msg',$this->upload->display_errors());
        }
    }
    

提交回复
热议问题