title: Yii Upload Image to Database
body: <p>Ive been trying to upload an image file into my data base which as the attribute image_name.  I want to be able to store the image and then store its file path into my database.. Ive tried many options on here.. but can't seem to figure out how to do it...</p>
  
  <p>This is what I've got so far if anyone could point me in the right direction that would be great...</p>
  
  <p>Thanks </p>
  
  <p>Model - </p>
  
  <pre><code>public function attributeLabels()
  {
      return array(
          'id' =&gt; 'ID',
          'movie_name' =&gt; 'Movie Name',
          'studio_id' =&gt; 'Studio',
          'country_id' =&gt; 'Country',
          'movie_rating_id' =&gt; 'Movie Rating',
          'map_pin_id' =&gt; 'Map Pin',
          'description' =&gt; 'Description',
          'title_image' =&gt; 'Title Image',
          'title_trailer_youtube_code' =&gt; 'Title Trailer Youtube Code',
          'release_date' =&gt; 'Release Date',
          'bg_colour_code' =&gt; 'Bg Colour Code',
          'text_colour_code' =&gt; 'Text Colour Code',
          'is_released' =&gt; 'Is Released',
          'is_advanced_booking_allowed' =&gt; 'Is Advanced Booking Allowed',
          'advanced_booking_start_date' =&gt; 'Advanced Booking Start Date',
          'advanced_booking_end_date' =&gt; 'Advanced Booking End Date',
          'domain_prefix' =&gt; 'Domain Prefix',
          'facebook_app_id' =&gt; 'Facebook App',
          'facebook_app_url' =&gt; 'Facebook App Url',
          'facebook_icon_image_url' =&gt; 'Facebook Icon Image Url',
          'facebook_text' =&gt; 'Facebook Text',
          'twitter_text' =&gt; 'Twitter Text',
          'booking_share_text' =&gt; 'Booking Share Text',
          'home_tracking_url' =&gt; 'Home Tracking Url',
          'shows_tracking_url' =&gt; 'Shows Tracking Url',
      );
  }
  </code></pre>
  
  <p>Controller -</p>
  
  <pre><code>    public function actionCreate()
  {
      $model=new Movie;
  
      // Uncomment the following line if AJAX validation is needed
      // $this-&gt;performAjaxValidation($model);
  
      if(isset($_POST['Movie']))
      {
          $model-&gt;attributes=$_POST['Movie'];
          $uploadedFile=CUploadedFile::getInstance($model,'title_image');
          $fileName = $uploadedFile;
          $model-&gt;title_image = $fileName;
          if($model-&gt;save())
              $uploadedFile-&gt;saveAs('http://localhost:8888/MY/Movies/title_image/'.$fileName);
              $this-&gt;redirect(array('view','id'=&gt;$model-&gt;id));
      }
  
      $this-&gt;render('create',array(
          'model'=&gt;$model,
      ));
  }
  </code></pre>