Page 1 of 1

Importing from CSV

Posted: Tue Apr 05, 2016 10:41 pm
by dcrobertson01
Hi - I have made a CVS file to import users so I can test out some of the features. When I try to import it, I get a warning:

Code: Select all

Only import from CSV files is currently supported.
I am using a csv file created with LibreOffice and exported as csv. Here is the start of the csv file:

Code: Select all

user_name,email,first_name,last_name,password
username01,username01@noaddress.com,fname01,surname01,password01
username02,child,fname02,surname02,password02
username03,child,fname03,surname03,password03
username04,username04@noaddress.com,fname04,surname04,password04
username05,child,fname05,surname05,password05
username06,username06@noaddress.com,fname06,surname06,password06
username07,child,fname07,surname07,password07
username08,child,fname08,surname08,password08
username09,child,fname09,surname09,password09
username10,username10@noaddress.com,fname10,surname10,password10
username11,child,fname11,surname11,password11
I have tried using fixed width fields, and various quoting combinations for the fields, but still no luck. I've added the file as an attachment.

I have not added the file - csv and txt files are not allowed. :-(

Cheers,

Don

Re: Importing from CSV

Posted: Wed Apr 06, 2016 12:15 am
by GregS
Does the file you're uploading actually have a .csv extension? (Any chance it's misspelled as .cvs?)

Assuming that it is correctly named, controllers/users_controller.php at line 314 checks that the file "type" provided by the browser is "text/x-csv". It's possible that your browser is supplying some other type. You could check by adding something like

Code: Select all

$this->log($this->data['file']['type']);
in there, and then look for this line in logs/error.log.

Re: Importing from CSV

Posted: Wed Apr 06, 2016 7:20 pm
by dcrobertson01
It does have a .csv extention. I tried with .txt and .CSV.

The error log (tmp/logs/error.log) says:

Code: Select all

2016-04-07 11:02:34 Error: text/csv
I think the test should be for a text/csv file - x-csv seems to be used as application/x-csv to indicate the file should be opened with an application.

see here http://mimeapplication.org/x-csv.html

and a discussion here: http://stackoverflow.com/questions/6654 ... csv-format

Changing line 316 of controllers/users_controller.php to

Code: Select all

			} else if ($this->data['file']['type'] != 'text/csv') {
lets me successfully complete a trial run.

Re: Importing from CSV

Posted: Wed Apr 06, 2016 7:26 pm
by GregS
I'll have to do some more reading and testing on this to sort it out, but I do know that the code as-is worked just fine for me when I wrote it. Bulk user import isn't a frequently-used feature, so it's possible that some standard (or, more likely, non-standard browser behaviour) has changed between then and now, or maybe you're using a browser that I didn't test with.

Important thing is that it's working for you right now! ;)