title: What is the proper way to upload a file using CUploadedFile
body: <p>I am following the tutorial <a href="http://www.yiiframework.com/wiki/2/how-to-upload-a-file-using-a-model/" rel="nofollow">http://www.yiiframework.com/wiki/2/how-to-upload-a-file-using-a-model/</a> for uploading a file. I have written the following code :</p>
  
  <pre><code>$menuitem-&gt;attributes = $_POST['MenuItems'];
  $menuitem-&gt;clientId = Yii::app()-&gt;user-&gt;clientId;
  $menuitem-&gt;image = CUploadedFile::getInstance($menuitem, 'image');
  if($menuitem-&gt;save()){
     $menuitem-&gt;image-&gt;saveAs(
         Yii::app()-&gt;getBasePath()."/../../".$menuitem-&gt;image-&gt;getName()
     );
  }
  </code></pre>
  
  <p>But the problem is that if a file with the same name exists on the same directory, the files is neither overwritten or saved with a different name.
  What I want is the new image say image.jpg, if a file of the same name exists, to be renamed to : <code>image_1.jpg</code></p>
  
  <p>Is it possible ? Please reply.</p>