如何限制上传文件的扩展名?Yii2


How to limit extensions to upload files? Yii2

我有一个代码:

<?=Html::activeHiddenInput($model, $attribute, $inputParams); ?>
<?=Html::fileInput($id, null, ['id' => $id, 'style' => 'display: none']); ?>

我需要限制扩展名来上传表单中的文件,例如:

True: jpeg, png, jpg
False: *

如何在Yii2中执行此操作?

在模型的规则中,

[['file'], 'file', 'extensions' => 'gif, jpg'],

更多信息,请访问http://stuff.cebe.cc/yii2docs/yii-validators-filevalidator.html