title: Delete and Show FileField via AJAX
body: <p>I would like to delete an image and re-show the uploaded field at update view (yii).</p>
  
  <ol>
  <li>there is an image which is uploaded.</li>
  <li>when the user delete this image. </li>
  <li>at that time the image will delete and the upload <code>$form-&gt;filefield</code> will appear at the image place.</li>
  </ol>
  
  <p>This is view</p>
  
  <pre><code>&lt;div id="forAjaxRefresh"&gt;&lt;img src="&lt;?php echo $file; ?&gt;" width="150px" /&gt;&lt;/div&gt;
  
  &lt;?php echo CHtml::ajaxLink('clickMe', array('ajax'), array('update'=&gt;'#forAjaxRefresh'));?&gt;
  </code></pre>
  
  <p>This is controller</p>
  
  <pre><code>public function actionAjax()
      {
          $model=new CompanyLicense('search');
          //$this-&gt;render('update', array('model'=&gt;$model,'test'=&gt;'test'), false, true);
          //echo "$form-&gt;labelEx($model,'file_path');
          //$form-&gt;fileField($model,'file_path', array('class'=&gt;'input-file')); 
          //$form-&gt;error($model,'file_path'); ";
          //echo "$form-&gt;labelEx($model,'file_path')";
  
          echo 'OK';
      }
  </code></pre>
  
  <p>When I tried like it. It was showing the 'OK' at . But I want to show the upload file field at . How could I do? Please help me.</p>
  
  <p>===============+++++++++++++++++++++++++++++++====================================</p>
  
  <p>latest mvc</p>
  
  <p>model nothing change</p>
  
  <p>Controller </p>
  
  <pre><code>public function actionAjax($id)
      {
          $model=new CompanyLicense();
          //$this-&gt;render('uploadfield', array());
          //echo "$form-&gt;labelEx($model,'file_path');
          //$form-&gt;fileField($model,'file_path', array('class'=&gt;'input-file')); 
          //$form-&gt;error($model,'file_path'); ";
          //echo "$form-&gt;labelEx($model,'file_path')";
  
  
          echo $this-&gt;renderPartial('uploadfield',array('model'=&gt;$model),false,true);
  
          /*
          $model=Company::model()-&gt;findByPk($_GET['id']);
  
          if($model){
              $file = '/images/'. $model-&gt;id . '/'. $model-&gt;file_path;
              unlink(dirname(__FILE__) . '/../../..'.$file);
          }
          &lt;br /&gt;
  */
  
  
      }
  </code></pre>
  
  <p>view (_form.php)</p>
  
  <pre><code>&lt;div class="form"&gt;
  
  &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
      'id'=&gt;'company-license-form',
      'enableAjaxValidation'=&gt;false,
      'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'),
  )); ?&gt;
  
      &lt;p class="note"&gt;Fields with &lt;span class="required"&gt;*&lt;/span&gt; are required.&lt;/p&gt;
  
      &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'company_id'); ?&gt;
          &lt;?php
              $records = Company::model()-&gt;findAll();
              $list = CHtml::listData($records, 'id', 'name');            
          ?&gt;     
          &lt;?php echo $form-&gt;dropDownList($model,'company_id', $list, array('prompt'=&gt;'Please select a Company')); ?&gt;
  
          &lt;?php echo $form-&gt;error($model,'company_id'); ?&gt;
      &lt;/div&gt;
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'license_no'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'license_no',array('size'=&gt;50,'maxlength'=&gt;50)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'license_no'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'license_name'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'license_name',array('size'=&gt;60,'maxlength'=&gt;200)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'license_name'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'annualfee'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'annualfee',array('size'=&gt;10,'maxlength'=&gt;10)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'annualfee'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
  
          &lt;?php echo $form-&gt;labelEx($model,'expire_date'); ?&gt;
          &lt;?php 
              $this-&gt;widget('zii.widgets.jui.CJuiDatePicker', array(
                  'name'=&gt;'expire_date',      
                  'model'=&gt;$model,
                  'value' =&gt; $model-&gt;expire_date, 
                  'options'=&gt;array(
                      'showAnim'=&gt;'fold',
                      'dateFormat' =&gt; 'yy-mm-dd',
  
                  ),
                  'htmlOptions'=&gt;array(
                      'style'=&gt;'height:20px;'
                  ),
              ));
              ?&gt;
          &lt;p&gt; Expire Date must be greater than Current Date.&lt;/p&gt;
          &lt;?php echo $form-&gt;error($model,'expire_date'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'notification_days'); ?&gt;
          &lt;?php echo $form-&gt;textField($model,'notification_days'); ?&gt;&lt;p&gt; Notification Days must be between 7 and 90.&lt;/p&gt;
          &lt;?php echo $form-&gt;error($model,'notification_days'); ?&gt;
      &lt;/div&gt;
  
      &lt;div class="row"&gt;
          &lt;?php echo $form-&gt;labelEx($model,'description'); ?&gt;
          &lt;?php echo $form-&gt;textArea($model,'description',array('rows'=&gt;6, 'cols'=&gt;50)); ?&gt;
          &lt;?php echo $form-&gt;error($model,'description'); ?&gt;
      &lt;/div&gt;
  
  
      &lt;div class="row" id="file_upload"&gt;
      &lt;?php
          $file = '/images/'. $model-&gt;id . '/'. $model-&gt;file_path;
  
          if (file_exists(dirname(__FILE__) . '/../../..'.$file)){
              echo '&lt;img src="http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . $file.'" width="150px" /&gt;' ;
  
          }else{
          ?&gt;
              &lt;div class="row"&gt;
              &lt;?php echo $form-&gt;labelEx($model,'file_path'); ?&gt;
              &lt;?php echo $form-&gt;fileField($model,'file_path', array('class'=&gt;'input-file')); ?&gt;
              &lt;?php echo $form-&gt;error($model,'file_path'); ?&gt;
              &lt;/div&gt;
          &lt;?php
          }
      ?&gt;
      &lt;/div&gt;      
  
      &lt;div id="forAjaxRefresh"&gt;&lt;img src="http://&lt;?php echo $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . $file; ?&gt;" width="150px" /&gt;&lt;/div&gt;
      &lt;div class="row buttons"&gt;
          &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;
      &lt;/div&gt;
  
  &lt;?php $this-&gt;endWidget(); ?&gt;
  
  &lt;/div&gt;&lt;!-- form --&gt;
  
  
  &lt;?php echo CHtml::ajaxLink('remove', array('ajax'), array('update'=&gt;'#forAjaxRefresh')); ?&gt;
  
  
  &lt;?php
  echo CHtml::ajaxLink( 'delete',  array( 'companylicense/ajax',  'id'=&gt;$model-&gt;id), array('type'=&gt; 'GET', 'update' =&gt; '#forAjaxRefresh') );
  ?&gt;
  
  &lt;?php echo CHtml::ajaxLink('remove2', array('url'=&gt;array('companylicense/ajax', 'id'=&gt;$model-&gt;id),
  ), array('update'=&gt;'#forAjaxRefresh')); ?&gt;
  </code></pre>
  
  <p>view (uploadfield.php)</p>
  
  <pre><code>&lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
          'id'=&gt;'company-license-form',
          'enableAjaxValidation'=&gt;false,
          'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'),
      )); ?&gt;
  &lt;?php echo $form-&gt;labelEx($model,'file_path'); ?&gt;
  &lt;?php echo $form-&gt;fileField($model,'file_path', array('class'=&gt;'input-file')); ?&gt;
  &lt;?php echo $form-&gt;error($model,'file_path'); ?&gt;
  &lt;?php $this-&gt;endWidget(); ?&gt;
  </code></pre>
  
  <p>Please help me!!!</p>