Validate uploaded file extension Yii2
<p>I'm trying upload specific files. </p>

<p>This is my code:</p>

<pre><code>[['file'], 'file', 'extensions' =&gt; ['pdf','php'], 'wrongExtension'=&gt;'pdf,php files only'],
</code></pre>

<p>When i try upload pdf, works great, but when i try upload php file say: "pdf,php files only". (after click in submit button)
I tried too, txt, js, etc...and i have the same problem.</p>

<p><strong>print_r($att->file);</strong></p>

<pre><code>yii\web\UploadedFile Object ( [name] =&gt; backup-restore-mysql.pdf [tempName] =&gt; C:\xampp\tmp\php8364.tmp [type] =&gt; application/pdf [size] =&gt; 310139 [error] =&gt; 0 )
yii\web\UploadedFile Object ( [name] =&gt; requirements.php [tempName] =&gt; C:\xampp\tmp\phpE22C.tmp [type] =&gt; application/octet-stream [size] =&gt; 5051 [error] =&gt; 0 )
</code></pre>

<p><strong>Controller:</strong></p>

<pre><code>if ($att-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $att-&gt;validate()){
 $att-&gt;file = UploadedFile::getInstance($att, 'file');
    if (!empty($att-&gt;file)){
        $extension = $att-&gt;file-&gt;extension;
        $att-&gt;Filename = $att-&gt;file-&gt;baseName;
        $att-&gt;Extension = $extension;
        $att-&gt;Size = $att-&gt;file-&gt;size;
        $att-&gt;C_Id = $id;

        if ($att-&gt;save()){
            if(!is_dir('files/'.$extension.'/')){
                mkdir(('files/'.$extension.'/'));
            }

            $att-&gt;file-&gt;saveAs('files/'.$extension.'/'.$att-&gt;file-&gt;name);
        }
    }
}
</code></pre>

<p>What i'm doing wrong?</p>