Extracting data from an uploaded .xls/.csv file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
elHelgo
Forum Newbie
Posts: 9
Joined: Tue Oct 03, 2006 3:52 pm

Extracting data from an uploaded .xls/.csv file

Post 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.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

fgetcsv() may be of interest.
Post Reply