title: Yii file field is empty
body: <p>I have file field exactly as <a href="http://www.yiiframework.com/wiki/2/how-to-upload-a-file-using-a-model/" rel="nofollow">this</a> link said in my project , i put exactly it's code and change every thing looks like it but when i want it's value by this code :</p>
  
  <blockquote>
  <pre><code>$uploadedFile = CUploadedFile::getInstanceByName($model,'image');
  </code></pre>
  </blockquote>
  
  <p>image is empty and i get this error :</p>
  
  <blockquote>
    <p>Illegal offset type in isset or empty</p>
  </blockquote>
  
  <p>I saw Yii add two field for file in the form and first one is hidden and empty why ?</p>
  
  <p>And i assume Yii get it as main image and so it is always empty , How could i get file field value.</p>
  
  <ul>
  <li><p>The only difference is it use CActiveRecord but i use CFormModel beacuse i dont have database in this project.</p></li>
  <li><p>I can access all the fields by $model->fieldname but this field is empty !!</p></li>
  </ul>
  
  <p>Edited:</p>
  
  <p>I find <a href="http://www.yiiframework.com/wiki/265/file-uploads-in-cform-form-builder/" rel="nofollow">this</a> tutorial but i cant use it because my form is in the controllers, view file and get a lot of variable from controller and this tutorials form seems clean:</p>
  
  <pre><code> $form = new CForm('application.views.fileUpload.uploadForm', $model);
  </code></pre>
  
  <p>My view:</p>
  
  <pre><code>&lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
                              'id'=&gt;'contacts-form',
                              'enableAjaxValidation' =&gt; false,
                              'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'),
                          )); ?&gt;
  
                              &lt;div class="fieldtext"&gt;
                                  &lt;div class="labelbox"&gt;
                                      &lt;?php echo $form-&gt;labelEx($model, Yii::t($this-&gt;language,'dialogboxname').":"); ?&gt;
                                  &lt;/div&gt;
                                  &lt;?php echo $form-&gt;textField($model,'name',array('value'=&gt;'aaa','size'=&gt;10,'maxlength'=&gt;50,'class'=&gt;'inputbox')); ?&gt;
                              &lt;/div&gt;
  
                              &lt;div class="fieldtext"&gt;
                                  &lt;div class="labelbox"&gt;
                                      &lt;?php echo $form-&gt;labelEx($model,Yii::t($this-&gt;language,'dialogboxemail').":"); ?&gt;
                                  &lt;/div&gt;
                                  &lt;?php echo $form-&gt;textField($model,'email',array('value'=&gt;'aaa@aa.com','size'=&gt;17,'maxlength'=&gt;50,'class'=&gt;'inputbox')); ?&gt;
                              &lt;/div&gt;
  
                              &lt;div class="fieldtext subjectbox"&gt;
                                  &lt;div class="labelbox"&gt;
                                      &lt;?php echo $form-&gt;labelEx($model,Yii::t($this-&gt;language,'dialogboxsubject').":"); ?&gt;
                                  &lt;/div&gt;
                                  &lt;?php echo $form-&gt;textField($model,'subject',array('value'=&gt;'aaa','size'=&gt;36,'maxlength'=&gt;50,'class'=&gt;'inputbox')); ?&gt;
                              &lt;/div&gt;
  
                              &lt;div class="fieldtext bodybox"&gt;
                                  &lt;div class="labelbox"&gt;
                                      &lt;?php echo $form-&gt;labelEx($model,Yii::t($this-&gt;language,'dialogboxbody').":"); ?&gt;
                                  &lt;/div&gt;
                                  &lt;?php echo $form-&gt;textArea($model,'body',array('value'=&gt;'aaa','rows'=&gt;6, 'cols'=&gt;35,'class'=&gt;'inputbox')); ?&gt;
                              &lt;/div&gt;
  
                              &lt;div class="fieldtext bodybox"&gt;
  
                                      &lt;?php echo $form-&gt;labelEx($model,'image'); ?&gt;
  
                                      &lt;?php echo $form-&gt;fileField($model, 'image'); ?&gt;
                              &lt;/div&gt;
  
                              &lt;?php if(CCaptcha::checkRequirements()): ?&gt;
                              &lt;div class="captchabox fieldtext"&gt;
  
                                  &lt;div&gt;
                                  &lt;?php echo $form-&gt;labelEx($model,Yii::t($this-&gt;language,'dialogboxconfirmcode').":"); ?&gt;
                                  &lt;?php $this-&gt;widget('CCaptcha',array(
                                          'showRefreshButton' =&gt; false,
                                          'clickableImage' =&gt; true,
  
                                      )); ?&gt;
                                          &lt;?php echo $form-&gt;textField($model,'verifyCode',array('size'=&gt;5,'maxlength'=&gt;5)); ?&gt;
  
                                  &lt;/div&gt;
  
                              &lt;/div&gt;
                              &lt;?php endif; ?&gt;
                              &lt;div class="contactbuttom"&gt;
                                  &lt;div class="submitcontactform buttomsize"&gt;
                                      &lt;?php echo CHtml::submitButton(Yii::t($this-&gt;language,'dialogboxsendbuttomn')); ?&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;?php $this-&gt;endWidget(); ?&gt;
  </code></pre>
  
  <p>My Model:</p>
  
  <pre><code>&lt;?php
  class ContactForm extends CFormModel {
      public $name;
      public $email;
      public $subject;
      public $body;
      public $image;
      public $verifyCode;
  
      /**
       * Declares the validation rules.
       */
      public function rules()
      {
          return array(
              // name, email, subject and body are required
              array('name, email, subject, body', 'required',
                      ),
              // email has to be a valid email address
              array('email', 'email'),
  
              array('image', 'file'),
      }
  
      public function attributeLabels()
      {
          return array(
              'verifyCode'=&gt;'Verification Code',
          );
      }
  
  }
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>...
  $this-&gt;model= new ContactForm;
  $model = $this-&gt;model;
  
      if(isset($_POST['ContactForm']))
      {
          $model-&gt;attributes=$_POST['ContactForm'];
  
          if($model-&gt;validate())
          {
              $name = $model-&gt;name;
              $email = $model-&gt;email;
              $subject = $model-&gt;subject;
              $body = $model-&gt;body;
  
              $uploadedFile = CUploadedFile::getInstanceByName($model,'image');
  
  ....
  </code></pre>
  
  <p>Funny thing is it check the rule but said it is empty.</p>