title: Yii validation tabular form can't upload files
body: <p>I'm having some problems when I try upload multiples files in multiples instances of my model (tabular way).</p>
  
  <p>I have a model called Files and a view that generate a form for multiple instances of that model. When I save  the form without "multpart/form-data", everything works, but if I put this parameter on form and submit it, the validation shows the message that "File cannot be blank."</p>
  
  <p>See my controller code bellow:</p>
  
  <pre><code>public function actionRegistration() {
    $company  = new Company;
    $contacts = $this-&gt;getModelItens('Contact', 3);
    $banks    = $this-&gt;getModelItens('Bank'   , 2);
    $files    = $this-&gt;getModelItens('File'   , 2);
  
    $company-&gt;scenario = 'create';
    if($_POST['Company']) {
      $company-&gt;attributes = $_POST['Company'];
      $valid = $company-&gt;validate();
      $valid = $this-&gt;validateModels($_POST['Contact'], $contacts) &amp;&amp; $valid;
      $valid = $this-&gt;validateModels($_POST['Bank'], $banks) &amp;&amp; $valid;
      $valid = $this-&gt;validateModels($_POST['File'], $files) &amp;&amp; $valid;
  
      if($valid) {
        if($company-&gt;save()) {
          $this-&gt;saveModels($contacts, $company-&gt;id);
          $this-&gt;saveModels($banks, $company-&gt;id);
          $this-&gt;saveModels($files, $company-&gt;id);
  
          $this-&gt;redirect('/obrigado');
        }
      }
    }
  
      $this-&gt;render('registration', array('company' =&gt; $company, 'contacts' =&gt; $contacts, 'banks' =&gt; $banks, 'files' =&gt; $files));
    }
  
  
  private function getModelItens($model_name, $times, $scenario = 'create') {
    $models = array();
    for($i = 0; $i &lt; $times; $i++) { 
      $models[$i]           = new $model_name; 
      $models[$i]-&gt;scenario = $scenario;
    }
    return $models;
  }
  
  private function validateModels($forms, $models) {
    $valid  = true;
    foreach($forms as $k =&gt; $form) { 
      $models[$k]-&gt;attributes = $form;
      $models[$k]-&gt;position   = $k;
      $valid = $models[$k]-&gt;validate() &amp;&amp; $valid;
    }
    return $valid;
  }
  
  private function saveModels($models, $company_id) {
    foreach($models as $k =&gt; $model) {
      $model-&gt;company_id = $company_id;
      if($model instanceOf File) {
        if($model-&gt;save()) $this-&gt;upload_file($model, "file"); 
      } else $model-&gt;save();
    }
  }
  
  
  private function upload_file($model, $field, $k) {
    $path = Yii::app()-&gt;basePath . "/../assets/files/companies/{$model-&gt;company_id}/";
  
    $file = CUploadedFile::getInstance($model, $field);
    if($file instanceof CUploadedFile) $model-&gt;$field = $file;
  
    if($model-&gt;$field instanceof CUploadedFile) {
      if(!file_exists($path)) exec("mkdir -p {$path}");
      $model-&gt;$field-&gt;saveAs($path . $model-&gt;$field);
    }
  }
  </code></pre>
  
  <p>I've  tried everything but I can't fix it, any suggestion?</p>
  
  <p>Thanks. </p>