I have an application in which there is a requirement of Uploading csv files.
Everything is working fine. I am uploading files successfully with extension .csv.
Now here is the problem. someone may try to upload exe file by changing its extension to .csv and upload to server. It is perfectly uploading. Some one suggested me to upload file by using mimetype. I follow this tutorial.
I am getting mimetype null for csv files.
So can you please help me how to upload only csv files.
Thanks in Advance
Well, you are ont he right track. You need to do some kind of file inspection instead of just trusting the file extension.
Either you have to program your own, or use a third party library (which is what you are doing).
If you keep with the third party framework, you must eb having a configuration issue. What the issue is I can’t tell from your description, as I don’t know the library.
If you are only interested in recognizing CSV files I would recommend something simple that at least you understand and can control. Such as this approach:
Assume that CSV files consist of 0..n lines with the same number of elements pr. line, separated by one of these characters: , ;
It’s quite unlikely that an EXE file would have this structure, unless somebody deliberately attack your system with knowledge of your implementation.
Read the first couple of lines.
Split them on the regexp ([,;]).
Check that the results have the same number of elements.
For extra safety, check that they split on the same character.