CodeIgniter - File upload required validation

前端 未结 6 646
旧时难觅i
旧时难觅i 2020-12-01 02:08

I have 2 text fields and 1 file upload that are all required. Everything works when I require just the text fields, but when I require the file upload the validation error s

6条回答
  •  抹茶落季
    2020-12-01 02:48

    you can use call back function, like this

      $this->form_validation->set_rules('userfile', 'Document', 'callback_file_selected_test');
    
        if ($this->form_validation->run() == FALSE) {
             //error
         }
        else{
               // success       
          }
    
    function file_selected_test(){
    
        $this->form_validation->set_message('file_selected_test', 'Please select file.');
        if (empty($_FILES['userfile']['name'])) {
                return false;
            }else{
                return true;
            }
    }
    

提交回复
热议问题