I've a page where in I ask users to upload tab separated csv file. But how do i ensure that tab separated csv file is uploaded. I need php validation for this. Can anyone help? Thanks in advance.
+1
A:
Apart from the usual safety measures when handling file uploads in PHP, try to parse it as CSV; if it succeeds, it is valid. One thing you may want to watch out for is files that are too large and might make your application eat up too much memory.
tdammers
2010-08-03 07:44:05
Parsing first N bytes will do.
Basilevs
2010-08-03 08:55:31
Not quite. After N bytes, you might still encounter invalid data (e.g. too many or too few columns). However, if the first few lines can be parsed without errors, chances are high that it is indeed a CSV file.
tdammers
2010-08-03 09:13:54
A:
By far the easiest way to do a rudimentary check would be to have them enter the column names in the first row, so you can check whether they match the columns you expect. But you'll still have to check whether the data they provide is valid...
wimvds
2010-08-03 08:07:40