I am uploading a file, how can I ensure that the file being uploaded is only in text format. i.e if the user changes the file extension of exe to txt, still then , my program should point out that this file is not a txt it is an exe. any one have any idea.
My requiremtn is to allow only txt,html or image files.
For text files you can check that the file does not contain any characters that are not part of the character sets you want to allow. Often that means only characters below 256 are allowed, but Uncode (or whatever other encoding might be used) complicate the matter a bit.
HTML files should have a DOCTYPE declaration at the beginning, although not all do.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Jan 16, 2001
Thanks for your post, I believe there must be some all in one utility to accomplish the task. I am already using Jakarta Common, may be this requiremetn is already present in the Commons.. i need to check.
One utility to identify file types by looking at the contents? After you look at this extremely comprehensive site you may think differently. There are a LOT of different file types, as you will see by browsing that site a bit, and the vast majority of them don't have a documented format that can be used to identify them. But you could certainly scratch the surface and attempt to identify some of the more common formats.