0

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?

Jota
  • 17,281
  • 7
  • 63
  • 93
Armeice
  • 31
  • 10

1 Answers1

-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.

Community
  • 1
  • 1
Alex
  • 5,364
  • 9
  • 54
  • 69