title: Yii Framework store/save submitted file to images folder
body: <p><strong>Hi, for the past 2 days i've been reading and reading lots of tutorials about saving files to folders in Yii, and neither of them have worked so far. I have the folowing form:</strong></p>
  
  <pre><code>&lt;div class="form"&gt;
  
  &lt;?php $form = $this-&gt;beginWidget('CActiveForm', array(
  'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data')
  )); ?&gt;
  
  &lt;?php echo $form-&gt;errorSummary($model); ?&gt;
  
  &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'Binaryfile'); ?&gt;
      &lt;?php echo $form-&gt;fileField($model,'uploadedFile'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'uploadedFile'); ?&gt;
  &lt;/div&gt;
  
  &lt;div class="row buttons"&gt;
      &lt;?php echo CHtml::submitButton($model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  endWidget(); ?>
  
  <p></p>
  
  <p><strong>The file field submits the code to a BLOB field in mysql database.
  The Controller is as follows:</strong></p>
  
  <pre><code>public function actionCreate()
  {
      $model=new Estudos;
  
      // Uncomment the following line if AJAX validation is needed
      // $this-&gt;performAjaxValidation($model);
  
      if(isset($_POST['Estudos']))
      {
          $model-&gt;attributes=$_POST['Estudos'];
          $model-&gt;binaryfile = CUploadedFile::getInstance($model,'binaryfile'); // grava na bd no campo binaryfile
          // $model-&gt;binaryfile-&gt;saveAs(Yii::app()-&gt;params['uploadPath']);
  
          if($model-&gt;save())
              $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
      }
  
      $this-&gt;render('create',array(
          'model'=&gt;$model,
      ));
  }
  </code></pre>
  
  <p><strong>And the Model is this one:</strong></p>
  
  <pre><code>public function rules()
  {
      // NOTE: you should only define rules for those attributes that
      // will receive user inputs.
      return array(
          array('fileName', 'length', 'max'=&gt;100),
          array('fileType', 'length', 'max'=&gt;50),
          array('binaryfile', 'safe'),
          // The following rule is used by search().
          // @todo Please remove those attributes that should not be searched.
          array('id, fileName, fileType, binaryfile', 'safe', 'on'=&gt;'search'),
      );
  }
  
  public $uploadedFile;
  // Gravar imagem na base de dados - cria blob field
  public function beforeSave()
  {
  
      if ($file = CUploadedFile::getInstance($this, 'uploadedFile'))
      {
          $this-&gt;fileName = $file-&gt;name;
          $this-&gt;fileType = $file-&gt;type;
          $this-&gt;binaryfile = file_get_contents($file-&gt;tempName);
      }
  
      return parent::beforeSave();
  }
  </code></pre>
  
  <p><strong>The code works fine to store a file as a BLOB field, but i need to change the code to store the file in images folder and next to display links that permits to open the file (pdf file) in any browser.
  To store the file in images folder i tryed saveAs() in my controller actionCreate but Yii freezes and the webpage becames blank with no error, just blank.</strong></p>
  
  <p>**Anyone can help me... I need this very very much. Many thanks in advance. **</p>