• Post Reply Bookmark Topic Watch Topic
  • New Topic

allow upload txt files only

 
priyanka jolly
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am writing a code to allow only txt files to upload.I have written a javascript to allow only .txt files to upload.But if the user gets cranky and renames an exe file to .txt file then on upload i have to prevent it as it results in uploading of junk data Can you please let me know is there a way to know the content type of the file being loaded or any other way i can prevent it. i am using commons-file upload jar
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On linux, there is the file program, to test files, and I guess, there is a win32-port of this program too, but you might do it yourself by parsing the bytes and rejecting junk.
Only few of the lower bytes 0-31 are legal in 'text'-files, as \n, \t, \r.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on advanced Java.

This post has been moved to a more appropriate forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!