I'm creating a script that will allow csv files to be uploaded; my problem is how to determine that the uploaded file is actually a .csv file. Found the url below and it has a few interesting points;
http://stackoverflow.com/questions/6654 ... csv-format
The option that stands out for me at this point is to validate the data in the file by using regular expressions - but i'm not sure if this is a workable option. The uploaded files will contain at least 1000 "records" at a time so using regex will probably slow things down significantly
Any ideas or suggestions on how to validate a csv file before uploading it?
Checking for a .csv file
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Checking for a .csv file
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Checking for a .csv file
I think they've probably nailed it; there's no real way short of parsing the file to be sure. I'd check MIME type against an array of possible values first, then try to parse the first line or two of the file. If they look OK, I'd assume the file was good.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Checking for a .csv file
Currently i loop through the file and if an array is present i process it; i agree with the combination option, i think i will implement it with my existing code.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering