Uploading an image in Codeigniter shows error The upload path does not appear to be valid

前端 未结 10 1644
独厮守ぢ
独厮守ぢ 2020-12-18 11:54
$config[\'upload_path\'] = site_path().\'photos/\';
$config[\'allowed_types\'] = \'gif|jpg|png|jpeg\';
$config[\'max_size\'] = \'2048\';
$this->load->library(\         


        
10条回答
  •  南方客
    南方客 (楼主)
    2020-12-18 12:29

    Try out this code in your Controller

    $config['upload_path'] = 'images'; //name of the uploading folder
    $config['allowed_types'] = 'jpeg|png|jpg'; 
    $config['file_name'] = 'name_for_file'; 
    
    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    
    if (!$this->upload->do_upload())
     {
      echo $this->upload->display_errors();
      exit;
     }
    else
     {
      $upload_data = $this->upload->data();
     } 
    

提交回复
热议问题