How to enable extension validation in yii2

im not a developer in yii2 and i want to enable upload files like php
i want to upload just files like image and pdf doc …

i tried this code but nothing happend : ```
[[‘file’], ‘file’, ‘extensions’ => ‘gif, jpg’],

maybe cause i dont where to put it , any way i think the upload is via ajax , so any help ?
thanks

help me please i can loose my job :frowning:

Give us some code of your controller, model and view

i think this is the view

<div class="row">
   <div class="col-lg-12">
   	<div class="caption-desc font-grey-cascade">
   		<?= Yii::t('app', 'Allowed types {pdf}, {png}, {jpg}. Maximun size {maxsize}',
   			[
   				'pdf'    => '<pre class="mt-code">pdf</pre>',
   				'png'    => '<pre class="mt-code">png</pre>',
   				'jpg'    => '<pre class="mt-code">jpg</pre>',
   				'maxsize'=> '<pre class="mt-code">3 MB</pre>'
   			]);
   		?>
   	</div>
   </div>
</div>
<div style="margin-top:20px"></div>
<div class="row" id="form-attachment">
   <div class="col-lg-12">
   	<?= backend\widgets\SelectFile::widget(
   	[
   		'id'		=> 'attachment',
   		'selectText'=> Yii::t('app','Select file'),
   		'changeText'=> Yii::t('app','Change'),
   		'removeText'=> Yii::t('app','Remove'),
   		'uploadText'=> Yii::t('app','Upload')
   	]); ?>
   </div>
</div>
<div class="row" style="display: none" id="msg-upload"></div>
<div style="margin-top:10px"></div>
<div class="row">
   <div class="col-lg-12">
   	<?php yii\widgets\Pjax::begin(
   		[
   			'id'             => 'pjax-attachments-'.$UserId,
   			'timeout'        => 999999999,
   			'enableReplaceState'=>false,
   			'enablePushState'=> false
   		]); ?>
   	<?=  
   	\common\widgets\GridView::widget([
   		'id'		   => 'grid-'.$UserId,
   	    'dataProvider' => $dataProvider,
   	    'layout'       => "{items}\n{pager}",
   	    'columns'	   => [
   	        [
   	            'label'     => Yii::t('app','File name'),
   	            'value'		=> function($data){
   	            	return $data->name;
   	            }
   	        ],
   	    	[
   	            'label'     => Yii::t('app','Upload date'),
   	            'value'		=> function($data){
   	            	return \Yii::$app->formatter->asDate($data->date);
   	            }
   	        ],
   	        [
   	        	'format'=> 'raw',
   	            'label' => Yii::t('app','Actions'),
                   'value' => function($data) use ($companyId){
                   	$url = $data->getWebPath($companyId);
                       return '<a data-pjax="0" target="_blank" id="'.$data->id.'" href="http://'.$url.'"><i class="material-icons left">visibility</i></a>';
                   }
   	        ]
   	    ]
   	]); 
   	?>
   	<?php yii\widgets\Pjax::end(); ?>
   </div>
</div>
<?php
$js  = <<<JS
$('#btn-attachment-upload').click(function(){
   $('div#msg-upload').html('').hide();
   var files   = $('#attachment input[type="file"]')[0].files[0];
   if( files != undefined ){
   	var formData= new FormData();
   	formData.append('files',files);
   	formData.append('User_id', $UserId);
   	$.ajax({
           type: 'post',
           url: '/users/attatchment',
           data: formData,
           cache: false,
           contentType: false,
           processData: false,
           dataType: 'json',
       }).done( function( result ){
       	var resultUpload = '<div class="col-lg-6">';
       	if( result.status == 'success' ){
       		resultUpload += '<div class="alert alert-success">';
       		resultUpload += '<i class="fa fa-check" aria-hidden="true"></i> ';
       		$('#form-attachment .fileinput').removeClass('fileinput-exists').addClass('fileinput-new')
       		$('#form-attachment .fileinput-filename').html('')
       		$('#attachment input[type="file"]').replaceWith($('#attachment input[type="file"]').val('').clone(true)).trigger('change')
       		$('.nav-tabs a[href="#attachment"]').trigger('shown.bs.tab');
       	}else{
       		resultUpload += '<div class="alert alert-danger">';
       		resultUpload += '<i class="fa fa-info" aria-hidden="true"></i> ';
       	}
       	resultUpload += result.msg+'</div></div>';
       	$('div#msg-upload').html(resultUpload).show();
       })
   }
});
$('#attachment input[type="file"]').change(function(){
   $('div#msg-upload').html('').hide();
});
JS;
$this->registerJs($js);