From: "Wayne E. Seguin" Date: 2007-07-18T23:33:33+09:00 Subject: Re: Validating an Image file is an image file --Apple-Mail-4-303588415 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jul 18, 2007, at 10:25 , John Joyce wrote: > I know how to validate a file based only on the file name dot > extension, but this seems wholly insecure to me. > I feel that just testing for .jpg, .png, .jpeg, .gif, etc... is not > enough. > Clearly renaming a file to anything at all is easy to do. > How can I read into the file and check to see if it is is actually > a file of a given image type? Is there file header info to look for ? > Such as a particular byte sequence at a particular location in the > file? > > > John Joyce Use the unix file command `file #{file_name}` example: > file the.gif the.gif: GIF image data, version 89a, 91 x 91 -- Wayne E. Seguin Sr. Systems Architect & Systems Admin wayneseguin@gmail.com --Apple-Mail-4-303588415--