title: delete image from folder when new image is uploaded for php yiiframework
body: <p>I am quite new to php yiiframework. I have users model where it takes users basic information including profile image but i have to delete a image file when I updates new image for my profile.
  I uploaded file by using following method.</p>
  
  <pre><code>public function actionUpdate()
      {
          $model=$this-&gt;loadModel($id);    
          $random = substr(number_format(time() * rand(),0,'',''),0,10);          
          if(isset($_POST['Users']))
          {                           
              $model-&gt;attributes=$_POST['Users'];             
              $uploadedFile=CUploadedFile::getInstance($model,'image_path');
              $fileName = $milliseconds. '-' .$random;
              $model-&gt;image_path = $fileName;
  
              if($model-&gt;save())              
                  $uploadedFile-&gt;saveAs(Yii::app()-&gt;basePath.'/../images/uploaded/'.$fileName);
                  $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
          }    
          $data = PanXCore::getDataForCreateUser();
          $userRoles = new UserRoles();
          $this-&gt;render('create',array(
              'model'=&gt;$model,
                  'roles' =&gt; $data['roles'],
                  'userRoles' =&gt; $userRoles               
          ));
      }
  </code></pre>