2017-02-12 76 views
0

我正在開發codeigniter項目。所有工作在我的本地主機上。現在我已經將所有的東西都轉移到了服務器上我也使用雲道Codeigniter Image上傳問題

問題是當我嘗試上傳圖像它顯示我空白屏幕。以下是我的控制器代碼。

// Add Data 
    function add(){ 
     $data['pageTitle']=$this->lang->line('siteTitle'); 
     // Breadcrumbs 
     $this->breadcrumbs->push('Dashboard','admin/dashboard'); 
     $this->breadcrumbs->push('Category List','admin/category/index'); 
     $this->breadcrumbs->push('Add Category','admin/category/add'); 
     // Load View 
     // Form Submit 
     $this->form_validation->set_rules('_cat_title','Title','required|is_unique[pu_project_category.c_title]'); 
     $this->form_validation->set_rules('_cat_slug','Slug','required'); 
     $this->form_validation->set_rules('_cat_desc','Description','required'); 
     if($this->form_validation->run()==TRUE){ 
      if($this->upload->do_upload('_cat_image')){ 
       $image=$this->upload->data(); 
       $image=$image['file_name']; 
      }else{ 
       $image='No Image'; 
      } 
      $data['resUpload']=$this->upload->display_errors(); 
      $data['res']=$this->Category_Model->add($image); 
     } 
     // Load View 
     $this->load->view('admin/common/header',$data); 
     $this->load->view('admin/common/left-sidebar',$data); 
     $this->load->view('admin/category/add',$data); 
     $this->load->view('admin/common/footer',$data); 
    } 

以下是配置代碼上傳文件,

// Upload Configuration 
$config['upload_path']   = './project_images/'; 
$config['allowed_types']  = 'gif|jpg|png|jpeg|zip'; 
$config['max_size']    = '2000'; 
$this->load->library('upload', $config); 
$this->upload->initialize($config); 

請幫我解決這個問題,並告訴我,我做錯了。

+0

http://stackoverflow.com/a/41604500/2275490 – Vickel

+0

http://stackoverflow.com/a/42011446/4232159 – Mohammad

回答

0

試試這個

public function add() 
{ 



     $this->form_validation->set_rules('_cat_slug','Slug','required'); 

    if($this->form_validation->run() == TRUE) 
      { 
        $this->load->model('welcome_model');//change this with your model 



       //image upload 
       $config['upload_path'] = './uploads/'; 
       $config['allowed_types'] = 'png|gif|jpg|jpeg'; 
       $config['max_size'] = '7000'; 
       $this->load->library('upload',$config); 
       if (! $this->upload->do_upload('image')) 
       { 
        $error = array('error' => $this->upload->display_errors()); 
        $this->load->view('upload_view', $error); //loads the view display.php with error 
       } 

       $upload_data=$this->upload->data(); 

       $image=$upload_data['file_name']; 

       $this->load->view('upload_view'); 

        $data= array(
        '_cat_slug' => $this->input->post('_cat_slug'), 
        'image' => $image 

       ); //loads view display.php with data 
       $this->welcome_model->registre($data);//change this with your model function name 
      } 


      else 
      { 

      echo validation_errors(); 


      } 

}

+0

謝謝您的回答但我已經嘗試了這個次數。它沒有解決我的問題。 –

+0

你在試這個代碼 –