-1

I tried to upload a video using codeigniter 3. but why I got an error "Column 'file' cannot be null" I have checked my codes, nothing wrong.. Please help me. here is my code

Model

 public function savevideo(){
    $post = $this->input->post();
    $this->file = $this->UploadVideo();
    return $this->db->insert($this->_tableigavideo, $this);
 }
 private function UploadVideo(){
    $config['upload_path']          = './video';
    $config['allowed_types']        = 'MP4';
    $config['overwrite']            = true;
    $config['max_size']             = 17500000; 

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

    if ($this->upload->do_upload('file')) {
        return $this->upload->data("file_name");
    }
}

Here is my Controller

public function addvideo(){
    $indikator = $this->IndikatorModel;
    $validation = $this->form_validation;
    $validation->set_rules($indikator->rules());

    if ($validation->run() == TRUE){
     $indikator->savevideo();
     $this->session->set_flashdata('success', 'Berhasil upload video');
     redirect('indikator/index/'.$idiga);
    }
}

Here is my View

      <label class="col-form-label col-sm-3" for="file"><b>Pilih File Mp4/Mov</b></label>
      <div class="col-sm-9">
        <input type="file" name="file" accept=".mp4">
      </div>
Vickel
  • 7,879
  • 6
  • 35
  • 56
  • and I got this error "POST http://localhost:8080/indikator/addvideo/12 500 (Internal Server Error)" in inspect element – Fitri Zakiyatul Hidayah Aug 08 '22 at 02:49
  • have you set enctype="multipart/form-data" in `form` element? https://stackoverflow.com/questions/4526273/what-does-enctype-multipart-form-data-mean – Doelmi Aug 08 '22 at 06:51
  • Code Snippets are not meant to be used to format your code! Code Snippets are runable **JavaScript**, **CSS** and **HTML** code blocks to help to create a minimal, complete, and verifiable example! [About Code Snippets](https://stackoverflow.blog/2014/09/16/introducing-runnable-javascript-css-and-html-code-snippets/) and [How do I format my code blocks?](https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks) – Vickel Aug 08 '22 at 15:15

1 Answers1

0

Check your database.. set your file column to null if you are not always sending image file. And if your are sending image file always then check it is going to db or not. Print statement and check.