I want the CSV file uploaded by one of our clients to be truly a CSV file in PHP. I handle the download myself. I am not bothered by malicious users, but I'm worried about those who try to download Excel workbooks. If I am mistaken, the Excel workbook and CSV can still have the same MIME, so checking this is not enough.
Is there one regular expression that can handle validation of a CSV file, is it really a CSV file? (I don’t need parsing ... what for PHP fgetcsv () for.) I have seen a few, but they are usually followed by comments like "this does not work for case X".
Is there any other better way to handle this?
(I expect the CSV to contain first and last names, department names ... nothing unusual.)
source
share