title: Yii2 - finfo_file(/tmp/phpqE6gyD): failed to open stream: No such file or directory on save after file upload
body: <p>I am getting following error, when I try to save data into db after file upload: </p>
  
  <pre><code>finfo_file(/tmp/phpqE6gyD): failed to open stream: No such file or directory 
  </code></pre>
  
  <p>This is the code:</p>
  
  <p>$userFolderPath = \Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . \Yii::$app->user->getIdentity()->iduser;</p>
  
  <pre><code>        $model = new CsFile();
          $files = UploadedFile::getInstances($model, 'files');
          $errors = [];
  
          if (!file_exists($userFolderPath))
              mkdir($userFolderPath, 0777, true);
  
          foreach($files as $file):
              $fileModel = new CsFile();
              $fileModel-&gt;files = $file;
  
              if($fileModel-&gt;validate()):
  
                  $filename = str_replace(' ', '_', $file-&gt;baseName);
  
                  if(file_exists($userFolderPath . DIRECTORY_SEPARATOR . $filename . "." . $file-&gt;extension)):
                       $filename .= "-" .uniqid();
                  endif;
  
                  $fileModel-&gt;files
                      -&gt;saveAs($userFolderPath .DIRECTORY_SEPARATOR. $filename . '.' . $fileModel-&gt;files-&gt;extension);
  
                  $fileModel-&gt;iduser    = Yii::$app-&gt;user-&gt;getIdentity()-&gt;iduser;
                  $fileModel-&gt;name      = $filename;
                  $fileModel-&gt;extension = $file-&gt;extension;
                  $fileModel-&gt;add_date  = date('Y-m-d H:i:s');
                  $fileModel-&gt;save();
  
              else:
  
              endif;
  
          endforeach;
  
          var_dump('&lt;pre&gt;', $errors, '&lt;/pre&gt;');
  </code></pre>