How to upload image in CodeIgniter?

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

In view

 
 

In con

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 14:11

    Simple Image upload in codeigniter

    Find below code for easy image upload

    public function doupload()
         {
            $upload_path="https://localhost/project/profile"  
            $uid='10'; //creare seperate folder for each user 
            $upPath=upload_path."/".$uid;
            if(!file_exists($upPath)) 
            {
                       mkdir($upPath, 0777, true);
            }
            $config = array(
            'upload_path' => $upPath,
            'allowed_types' => "gif|jpg|png|jpeg",
            'overwrite' => TRUE,
            'max_size' => "2048000", 
            'max_height' => "768",
            'max_width' => "1024"
            );
            $this->load->library('upload', $config);
            if(!$this->upload->do_upload('userpic'))
            { 
                $data['imageError'] =  $this->upload->display_errors();
    
            }
            else
            {
                $imageDetailArray = $this->upload->data();
                $image =  $imageDetailArray['file_name'];
            }
    
         }
    

    Hope this helps you to upload image

提交回复
热议问题