Hi, I got an issue while I was using File Validator extension. I make an import feature. When I set rule to validate file extension is sql, I get a error message "Only files with these extensions are allowed: sql". This is my code
Controller
public function actionIndex()
{
$model = new BackupForm();
if (Yii::$app->request->isPost) {
$model->importFile = UploadedFile::getInstance($model, 'importFile');
if ($model->import()) {
Yii::$app->session->setFlash('success','Import successful');
}
}
return $this->render('index', ['model' => $model]);
}
Model
class BackupForm extends Model
{
public $importFile;
public function rules()
{
return [
[['importFile'], 'file', 'skipOnEmpty' => false, 'extensions' => 'zip, sql']
];
}
public function import()
{
if (!$this->validate()) {
return false;
}
// Execute importing
}
}
As you can see in your rules function, you defined that only .zip and .sql files are allowed for upload. If you try to upload an image, then you will get the error you wrote. Change the following line: