title: Yii - How to upload a csv to save in database?
body: <p>i'm with some troubles figuring out how to read the CSV file that I upload, probably i'm missing something in my Controller code.</p>
  
  <pre><code>  public function actionImport() {
      $model = new Produtos;
      $this-&gt;render('import', array('model' =&gt; $model) );
  
      if( isset($_FILES['csv_file']) ) {
  
        $handle = fopen($_FILES['csv_file']['tmp_name'], 'r');
  
        if ($handle) {
          while( ($line = fgetcsv($handle, 1000, ";")) != FALSE) {
              $model-&gt;codigo          = $line[0];
              $model-&gt;nome            = $line[1];
              $model-&gt;descricao       = $line[2];
              $model-&gt;stock           = $line[3];
              $model-&gt;data_reposicao  = $line[4];
  
              $model-&gt;save();
          }        
        }
        fclose($handle);
      }
  
    }
  </code></pre>
  
  <p>This is only saving me the last line in the CSV... please some help!</p>
  
  <p>Any help will be really appreciated.</p>
  
  <p>Thank you</p>