2017-02-12 7 views
0

私はcodeigniterプロジェクトに取り組んでいます。すべて私のlocalhostで動作しています。今私はサーバー上のすべてのものをシフトしました。私はまた、雲のファイルを使用しています。Codeigniter画像アップロードの問題

問題は、画像をアップロードしようとすると、空白の画面が表示されます。以下は私のコントローラコードです。

// 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

あなたはこのコードを試していますか –

関連する問題