2016-03-24 8 views
0

同じフォームに別のファイルをアップロードしようとしています。自分のディレクトリにファイルを追加し、データベースにファイル名を追加したい。私はディレクトリにファイルをアップロードすることができますが、データベースには動作しません。同じフォームに異なるファイルをアップロードする方法

この私のコントローラ

function tambahdata() 
{ 
    $this->load->view('vtambah_mastersub'); 
    if ($this->input->post('submit')) { 
     if (!empty($_FILES['picture']['name'])) { 
      $config['upload_path'] = './assets/uploads'; 
      $config['allowed_types'] = 'gif|jpg|jpeg|png'; 
      $config['max_size'] = '40000'; 
      $config['max_width'] = '1288'; 
      $config['max_height'] = '1288'; 
      $config['file_name'] = "file_" . time(); 
      $this->load->library('upload'); 
      $this->upload->initialize($config); 
      // if there was an error, return and display it 
      if (!$this->upload->do_upload('picture')) { 
       echo "errornya : "; 
       echo $this->upload->display_errors(); 
      } else { 
       echo "sukses"; 
       $gbr = $this->upload->data(); 
       $data = array(
        'nm_gbr' => $gbr['file_name'], 
        'tipe_gbr'=>$gbr['file_type'], 
       ) ; 
      } 
     } 
     if (!empty($_FILES['pdf']['name'])) { 
      $config['upload_path'] = './assets/uploads'; 
      $config['allowed_types'] = 'pdf'; 
      $config['max_size'] = '40000'; 
      $config['max_width'] = '1288'; 
      $config['max_height'] = '1288'; 
      $config['file_name'] = "file_" . time(); 
      $this->load->library('upload'); 
      $this->upload->initialize($config); 
      // if there was an error, return and display it 
      if (!$this->upload->do_upload('pdf')) { 
       echo "errornya : "; 
       echo $this->upload->display_errors(); 
      } else { 
       echo "sukses"; 
       $pdf = $this->upload->data(); 
       $dataa = array(
        'nm_pdf' => $pdf['file_name'], 
        'tipe_pdf' => $pdf['file_type'], 
       ); 
      } 
     } 
     $this->m_mastersub->tambah($data,$dataa); 
     redirect('mastersub'); 
    } 
} 

この私のモデル

function tambah($gambar,$pdf){ 
    $kd_mastersub = $this->input->post('kd_mastersub'); 
    $nama = $this->input->post('nama'); 
    $picture = $gambar['nm_gbr']; 
    $deskripsi = $this->input->post('deskripsi'); 
    $pdf = $pdf('nm_pdf'); 
    $video = $gambar('nm_video'); 
    $drive = $gambar('nm_drive'); 

    $data = array(
     'kd_mastersub' =>$kd_mastersub, 
     'name_cate' =>$nama, 
     'picture' => $picture, 
     'description' =>$deskripsi, 
     'pdf' => $pdf, 
     'video' => $video, 
     'drive' => $drive 

    ); 
    $this->db->insert('tbl_mastersub',$data); 
} 

この私のフォーム

  <div class="row form-group"> 
        <div class="col-md-6 text-left"> 
         <label>Picture </label> 
        </div> 
        <div class="col-md-10 text-left"> 
         <input type="file" name="picture" /> 
        </div> 
       </div> 
       <div class="row form-group"> 
        <div class="col-md-6 text-left"> 
         <label>PDF </label> 
        </div> 
        <div class="col-md-10 text-left"> 
         <input type="file" name="pdf" /> 
        </div> 
       </div> 

この私のエラー

enter image description here

いずれかがこの問題を解決するために私を助けてくださいすることができ、いくつかのタイプミスがあなたのコード であるように見えるのおかげ

+0

これを試して当然の質問はどのようにあなたの '$ことwoule db-> insert() 'は動作します –

+0

私は自分のモデルでそれを行っていました –

+0

はい$ this-> db-> insert( 'tbl_mastersub'、$ data);'が表示されますが、どのように動作しますか? –

答えて

0

ではなく

function tambah($gambar,$pdf){ 
    $kd_mastersub = $this->input->post('kd_mastersub'); 
    $nama = $this->input->post('nama'); 
    $picture = $gambar['nm_gbr']; 
    $deskripsi = $this->input->post('deskripsi'); 
    $pdf = $pdf['nm_pdf']; 
    $video = $gambar['nm_video']; 
    $drive = $gambar['nm_drive']; 

    $data = array(
     'kd_mastersub' =>$kd_mastersub, 
     'name_cate' =>$nama, 
     'picture' => $picture, 
     'description' =>$deskripsi, 
     'pdf' => $pdf, 
     'video' => $video, 
     'drive' => $drive 

    ); 
    $this->db->insert('tbl_mastersub',$data); 
} 
関連する問題