keboola / php-csv

CSV reader/writer
MIT License
135 stars 35 forks source link

Invalid line break. Please use unix \n or win \r\n line breaks. #12

Closed lstables closed 9 years ago

lstables commented 10 years ago
 public function postUpload ()
  {
     if ( Input::hasFile('file') )
    {
        DB::transaction(function()
        {
            // Clear out what we have written
            DB::table('wc_program')->delete();

            $csv = new CsvFile( Input::file('file')->getRealPath() );

            // Get the csv headers and move to the next line (the start of actual data)
            $columns = $csv->getHeader();
            $csv->next();

            // Loop through the rows creating / saving a record for each
            while( $csv->valid() )
            {
                $row = $csv->current();
                $pc = new Programmes();

                for( $i=0; $i<count($columns); $i++ )
                {
                    $pc->columns[$i] = $row[$i];
                }

                $pc->save();
                $csv->next();
            }
        });

        return Redirect::to('admin/programmes')->with('flash_success', 'Upload completed &amp; new data inserted.');
    }
}

How can that be?

tim-massey commented 9 years ago

Did you get anywhere with this? I am getting the same message.

lstables commented 9 years ago

Yes I changed that out to use this great package - https://github.com/thephpleague/csv

tim-massey commented 9 years ago

Damn, I'm still on PHP 5.3 for the moment so can't use it. That was my first choice.