How to get the uploaded file in Controller which is uploaded through yii\helpers\Html::fileInput in Yii2
<p>In my form I have used below code:</p>

<pre><code>&lt;?php echo Html::fileInput('imageFile', '', array('id' =&gt; 'contentForm_imageFile' )) ?&gt;
</code></pre>

<p>and I tried to get the file in the controller with below code:</p>

<pre><code>$newsModel-&gt;imageFile=UploadedFile::getInstance(Yii::$app-&gt;request-&gt;post('imageFile'), 'imageFile');
    $newsModel-&gt;imageFile-&gt;saveAs( 'uploads/'.$newsModel-&gt;file-&gt;basename.'.'.$newsModel-&gt;file-&gt;extension );
</code></pre>

<p>But I am getting this error when using above code to save the file:</p>

<blockquote>
  <p>Call to a member function saveAs() on null</p>
</blockquote>

<p>since the API document of <code>yii\web\UploadedFile</code> says that:</p>

<blockquote>
  <p>getInstance() Returns an uploaded file for the given model attribute,
  The file should be uploaded using
  yii\widgets\ActiveField::fileInput().</p>
</blockquote>

<p>So how can I get the uploaded file which is uploaded through <code>yii\helpers\Html::fileInput</code>?</p>