Hi All,
I have a form for user to upload CSV file. I want to make this upload compulsory but do not want to save this CSV file into my system, I just want to read CSV content and save the data into database table. When I run save(), it prompting I need to upload a file but in fact I had selected the file to upload but still prompt error. When I remove "csvfile" attribute from model, it will work fine and able to save without issue. Is there any way to resolve this issue?
Error when save:
Array ( [csvfile] => Array ( [0] => Please upload a file. ) )
Admin controller :
$model->form_id=$_POST[‘Accesscontrol’][‘form_id’];
$model->form_field=$_POST[‘Accesscontrol’][‘form_field’];
$model->rec_date=date("Y-m-d H:i:s");
$model->save();
The following rules in Model will prompt error need to upload file
public function rules()
{
// file max 5 Mb
return [
[['form_id','form_field'], 'required'],
[['form_id'], 'integer'],
[['form_field'], 'string', 'max' => 20],
[['csvfile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'csv', 'maxSize'=>'5000000'],
[['csvfile'], 'required']
];
}
The following rules in Model working fine after remove "csvfile"
public function rules()
{
// file max 5 Mb
return [
[['form_id','form_field'], 'required'],
[['form_id'], 'integer'],
[['form_field'], 'string', 'max' => 20],
];
}