I have an uploader in JSP, and through this I can upload several kinds of file. I need to perform a control (I think with regular expression, just a simple check on file extension) where the JSP engine could read the content of the file and understand if the file is an image or plain text file. I can accept only plain text (text or XML) and discard all the other kind of files. Could someone help me or suggest another way to do that?
Asked
Active
Viewed 191 times
0
-
consider an answer like this one... http://stackoverflow.com/questions/567757/how-do-i-distinguish-between-binary-and-text-files – Les Jun 25 '15 at 16:19
-
With REGEX, is possible do this control? – Armeice Jun 26 '15 at 14:20
1 Answers
-1
As a very basic check you could verify the file extension with something like \.txt$
, however this doesn't prevent people from uploading different filetypes with a .txt extension. You might be better off by checking the mimetype of the file uploaded, a JSP example can be found here.