2017-07-27 14 views
-1

これはコードです、私の写真はデータベースに挿入できません。私はどこに問題があるのか​​分からない。CodeIgniter私の写真はデータベースに挿入できません

コントローラー:

public function add_gambar() 
    { 
     $config['upload_path'] = './assets/img/'; 
     $config['allowed_types'] = 'jpg|png'; 
     $config['max_size'] = '2000'; 
     $config['max_width'] = '1024'; 
     $config['max_height'] = '768'; 

     $this->load->library('upload', $config); 

     if (!$this->upload->do_upload('gambar')) 
     { 
      $this->Gambarhome_model->tambah_gambar_error(); 
      redirect('gambarhome/','refresh'); 
     } 
     else 
     { 

      $this->Gambarhome_model->tambah_gambar(); 
      redirect('gambarhome/','refresh'); 
     } 
    } 

モデル:

function tambah_gambar(){ 
     $date = $this->upload->data(); 
     $data=array(
     'judul'=>$this->input->post('judul'), 
     'desc'=>$this->input->post('desc'), 
     'gambar'=>$date['file_name'] 
     ); 
     $this->db->insert('gambarhome',$data); 
    } 

誰かplsは私を助けて、ありがとうございました!

答えて

0

アップロードライブラリをロードし、これを使用してみてください。

0

BLOBデータ型を使用

データベーステーブルにイメージを保存するために使用したデータ型はありますか? LONGBLOBを使用してバイナリラージオブジェクトをテーブルに格納します。 1Mb以上のイメージファイルを保存する場合は、サーバーの設定ファイルに必要な変更を加えることで実現できます。あなたがそれを使用していない場合は、LONGBLOBを試してみてください。

$this->upload->initialize($config); 

、その後、条件場合に画像をアップロードしてみてください:

$config['upload_path'] = './assets/img/'; 
//make sure that you have given the correct path 
関連する問題