Friday, 5 March 2010

To test for MIME or to not test for MIME

So I was looking to check if a file to be uploaded is of the type csv and I thought that I'd be able to check the MIME type of the file. Nothing is ever that easy though. The experiments I made pointed to the MIME being of the type application/, upon further reading though I discovered that actually the MIME type could be text/tab-separated-values or (the preferred choice, it would seem) text/csv.

So I could use lots of nice logical ORs or just sack the whole thing of looking at MIME types and just check the extension of the file using substr(strrchr($fileName, '.'), 1), thanks PHP MySQL Tutorial.

No comments:

Post a Comment