0

I am developing an application in cakephp where I want to import the csv file and save the data into database.

So I need some help in reading csv file into an array after which I will do some validation and insert data into database.

I have searched a lot but could not find the solution.

Thanks in advance.

Dinesh Patil
  • 615
  • 2
  • 15
  • 37
Rajput Pavan
  • 175
  • 1
  • 2
  • 10

2 Answers2

5

You should use CakePHP's already-existing csv datasource in a custom model.

It is here - https://github.com/cakephp/datasources/blob/master/Model/Datasource/CsvSource.php

See here for how to use them.

Then you can just use your normal $model->find() operations on it! Simple!

Timber
  • 859
  • 9
  • 25
Ivo
  • 5,378
  • 2
  • 18
  • 18
1

Try with fgetcsv(), here's the doc: fgetcsv()

ulentini
  • 2,413
  • 1
  • 14
  • 26