Page 1 of 1

Extracting data from an uploaded .xls/.csv file

Posted: Wed Feb 28, 2007 10:50 am
by elHelgo
I have an upload form on my page that excepts .xls or .csv files, and I need to find a way to extract the rows of the file and store them in a database.

I have done this the reverse way (pulling items from mysql and exporting as .xls files), but I'm not sure how to parse the values out of the file that is uploaded.

If anyone has encountered this, and knows a simple (or complex) way to get these values, that information would be greatly appreciated in advance.

Thanks.

Posted: Wed Feb 28, 2007 11:00 am
by mikeq
well start by looking at the PHP file functions to read each line of the file.

If the fields in the file are separated by a common character i.e. a comma ,

then use that with the explode() function to return an array of field values on each line of the file you read.

with the array returned from the explode function use that to insert into your database.

move onto the next line in your file.

repeat till finished.

Posted: Wed Feb 28, 2007 11:01 am
by feyd
fgetcsv() may be of interest.