So I am wanting to allow users to:
1. Upload a .csv file (mystudents.csv)
2. Import the rows in the .csv
3. Create a PHP array for all this
4. Insert this information into a database
I have the following code to upload the file and create the array.
public function studentImport()
{
ini_set('auto_detect_line_endings', TRUE);
$config['upload_path'] = './static/files/importFiles';
$config['allowed_types'] = '*';
$config['max_size'] = '800';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
var_dump($this->upload->display_errors());
}
else
{
$data = $this->upload->data();
$file_path = './static/files/importFiles/'.$data['file_name'];
$rows = array_map('str_getcsv', file($file_path));
if($rows){
$header = array_shift($rows);
$csv = array();
foreach($rows as $row) {
$csv[] = array_combine($header, $row);
}
var_dump($csv);
}
}
}
The file gets uploaded just fine, but the errors happens with the line: $rows = array_map('str_getcsv', file($file_path));
And that error is:
array_map() [function.array-map]: The first argument, 'str_getcsv', should be either NULL or a valid callback
What do I need to do to make this work out?