How to upload image in CodeIgniter?

后端 未结 7 1159
天涯浪人
天涯浪人 2020-11-30 13:56

In view

 
 

In con

7条回答
  •  甜味超标
    2020-11-30 14:06

    Below code for an uploading a single file at a time. This is correct and perfect to upload a single file. Read all commented instructions and follow the code. Definitely, it is worked.

    public function upload_file() {
        ***// Upload folder location***
        $config['upload_path'] = './public/upload/';
    
        ***// Allowed file type***
        $config['allowed_types'] = 'jpg|jpeg|png|pdf';
    
        ***// Max size, i will set 2MB***
        $config['max_size'] = '2024';
    
        $config['max_width'] = '1024';
        $config['max_height'] = '768';
    
        ***// load upload library***            
        $this->load->library('upload', $config);
    
        ***// do_upload is the method, to send the particular image and file on that 
           // particular 
           // location that is detail in $config['upload_path']. 
           // In bracks will set name upload, here you need to set input name attribute 
           // value.***
    
        if($this->upload->do_upload('upload')) {
           $data = $this->upload->data();
           $post['upload'] = $data['file_name'];
        } else {
          $error = array('error' => $this->upload->display_errors());
        }
     }
    

提交回复
热议问题