user3627265
user3627265

Reputation: 191

Check if the file is a valid CSV file

I have a CSV file, which is converted from a UNICODE to CSV file. I did this to process UTF-8 character. So here is the problem, I have a CSV file but when I tried to upload it, seems like it is not accepted as a CSV file. The csv file is somewhat read as a UNICODE from it's origin. When I used this condition to validate the file, it is bypass and generate an error, This condition works just fine on other instances.

 $mimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv');
 if( !empty($_FILES['csv_attach']['tmp_name']) && in_array($_FILES['csv_attach']['type'],$mimes))
{
                          /* some codes */
}

Now the question is that, how can you validate if the file is a valid CSV file, not a UNICODE text file? Or how can you validate if the file is a UNICODE TEXT? That's what I am thinking for the solution, just to validate the file if it is a UNICODE text or not. Am I missing something?

Upvotes: 0

Views: 3458

Answers (1)

user636044
user636044

Reputation:

Unicode is standard of encoding text.

Mime types, like text/csv are a method of conveying what is in a file.

You're mixing up two ideas here and your question makes no sense.

There is no official standard for CSV files, though rfc4180 might help.

There might be services that can validate the content of your CSV as discussed in this question: known services to validate csv file

Upvotes: 2

Related Questions