This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

validate a file extension  RSS feed

 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I doing a server that upload and saves files, it's working fine.

But, I need to let only some extension (like txt and jpg), I'm using the file extension, if it's different I refuse, but a user can rename the file extension before the upload and bypass it.

I found a software called JMimeMagic, it's good, but works with most of thw files, but some time doesn't validate some real txt.

works like this:



any good solution/software for that?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how JMimeMagic works, but if it's image formats you need to deal with, have a look at the ImageInfo class. It identifies a number of image formats based on the contents, not on the name or MIME type.
 
Mike Phillip
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for reply.

Well, it's most image and text. With images the JMimemagic is great, the problem is with txt, some times it fails.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does it fail?
Accept a file as txt which isn't?
Deny a file, which is a txt-file?

How is it identified, if not as txt?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!