title: Uploading images to database
body: <p>I am quite new to Yii and I'm having some problems.</p>
  
  <p>I'm trying to upload images to the database following the <a href="http://www.yiiframework.com/wiki/95/saving-files-to-a-blob-field-in-the-database/" rel="nofollow">wiki</a>.
  However, I can't seem to make it work. It always sees that there is nothing being uploaded.</p>
  
  <p>Here is my code for the model:</p>
  
  <pre><code>public $uploadedFile;
  
  /**
  * Saves the name, size, type and data of the uploaded file
  */
  public function beforeSave()
  {
      if($file=CUploadedFile::getInstance($this,'uploadedFile'))
      {
          $this-&gt;image_name=$file-&gt;name;
          $this-&gt;image_type=$file-&gt;type;
          $this-&gt;image_size=$file-&gt;size;
          $this-&gt;image=file_get_contents($file-&gt;tempName);
      }
      return parent::beforeSave();
  }
  </code></pre>
  
  <p>Controller for Create:</p>
  
  <pre><code>public function actionCreate()
  {
      $model=new Subdivision;
  
      // Uncomment the following line if AJAX validation is needed
      // $this-&gt;performAjaxValidation($model);
  
      if(isset($_POST['Subdivision']))
      {
          $model-&gt;attributes=$_POST['Subdivision'];
          $model-&gt;image = CUploadedFile::getInstance($this,'image');
  
          if($model-&gt;save())
              $this-&gt;redirect(array('view','id'=&gt;$model-&gt;subdivision));
      }
  
      $this-&gt;render('create',array(
          'model'=&gt;$model,
      ));
  }
  </code></pre>
  
  <p>and my form code:</p>
  
  <pre><code>    &lt;div class="row"&gt;
      &lt;?php echo $form-&gt;labelEx($model,'uploadedFile'); ?&gt;
      &lt;?php echo $form-&gt;fileField($model,'uploadedFile'); ?&gt;
      &lt;?php echo $form-&gt;error($model,'uploadedFile'); ?&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>can anyone help?</p>