How to upload image in CodeIgniter?

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

In view

 
 

In con

7条回答
  •  青春惊慌失措
    2020-11-30 14:14

    //this is the code you have to use in you controller 
    
            $config['upload_path'] = './uploads/';  
    
    // directory (http://localhost/codeigniter/index.php/your directory)
    
            $config['allowed_types'] = 'gif|jpg|png|jpeg';  
    //Image type  
    
            $config['max_size'] = 0;    
    
     // I have chosen max size no limit 
            $new_name = time() . '-' . $_FILES["txt_file"]['name']; 
    
    //Added time function in image name for no duplicate image 
    
            $config['file_name'] = $new_name;
    
    //Stored the new name into $config['file_name']
    
            $this->load->library('upload', $config);
    
            if (!$this->upload->do_upload() && !empty($_FILES['txt_file']['name'])) {
                $error = array('error' => $this->upload->display_errors());
                $this->load->view('production/create_images', $error);
            } else {
                $upload_data = $this->upload->data();   
            }
    

提交回复
热议问题