Allow users to import csv files

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
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Allow users to import csv files

Post by Pavilion »

Hello everyone:

The database project I am working on needs to include the capability for site users to import .csv files into the mySQL database.

Does anyone know of some good instructions on the web for this type of coding?

Thank you:

Pavilion
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Allow users to import csv files

Post by Celauran »

You'll want to take a look at fgetcsv(). Just remember, never trust user input! Make sure everything is properly type cast and sanitized. Consider using prepared statements.
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Re: Allow users to import csv files

Post by Pavilion »

Thanks Celauran - I did some research on fgetcsv() and ended up finding this. Do coders use these kinds of "classes" very much?

And if classes can be helpful in the coding process, how do you evaluate them before downloading?

Thanks Much - Pavilion
qeemat
Forum Newbie
Posts: 10
Joined: Sat Feb 18, 2012 1:12 am

Re: Allow users to import csv files

Post by qeemat »

A comma-separated values (CSV) file stores tabular data (numbers and text) in plain-text form. Plain text means that the file is a sequence of characters, with no data that has to be interpreted instead, as binary numbers. A CSV file consists of any number of records, separated by line breaks of some kind; each record consists of fields, separated by some other character or string, most commonly a literal TAB or comma. Usually, all records have an identical sequence of fields.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Allow users to import csv files

Post by Celauran »

Pavilion wrote:Thanks Celauran - I did some research on fgetcsv() and ended up finding this. Do coders use these kinds of "classes" very much?
Looks interesting. Makes sense to make use of existing tools rather than constantly reinventing the wheel, no?
Pavilion wrote:And if classes can be helpful in the coding process, how do you evaluate them before downloading?
Looks through the source to see what it does and how it's written.
Post Reply