title: How to create a directory inside a directory in yii2 and upload file into that directory
body: <p>I have a form</p>
  
  <pre><code>  &lt;?php $form = ActiveForm::begin(['options' =&gt; ['enctype' =&gt; 'multipart/form-data']]); ?&gt;
   &lt;?php echo $form-&gt;field($userformmodel, 'user_image')-&gt;fileInput(); ?&gt;
   &lt;?= Html::submitButton('Submit', ['class' =&gt; 'btn btn-primary']) ?&gt;
   &lt;?php ActiveForm::end(); ?&gt;
  </code></pre>
  
  <p>I am uploading a file in the form and submit</p>
  
  <pre><code>In the model I have written the code as
  
   public function rules()
  {
      return [
          [['user_image'], 'file', 'skipOnEmpty' =&gt; false, 'extensions' =&gt; 'png, jpg']
      ];
  }
  
   public function upload()
  {
      if ($this-&gt;validate()) {
          $this-&gt;user_image-&gt;saveAs('uploads/' . $this-&gt;user_image-&gt;baseName . '.' . $this-&gt;user_image-&gt;extension);
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>In my controller</p>
  
  <pre><code> public function actionProfile()
  {
   $model = new UserProfile();
   $userformmodel = new UserForm();
   $model-&gt;user_image = UploadedFile::getInstance($userformmodel, 'user_image');
   if($model-&gt;save(false))
                  {
                  $model-&gt;upload();        
                  }
   }
  </code></pre>
  
  <p>This is just creating a directory called <code>uploads</code>. But I want to create a directory inside uploads directory for each user i.e, based upon the primary key in database table <code>user</code> I want to create and name the directory name.</p>
  
  <p>Example, if the user registering is saved as primarykey <strong>4</strong>, then a directory with name <strong>4</strong> must be created and the file he uploads must be saved into that directory.</p>
  
  <p>How to make this happen? please help.</p>