holotko wrote:

> This is very simple however, is there an relativly easy,
> straightforward way to determine whether or not the file in question
> is an image file? By determining whether the file is an image file or
> not I mean specifically something more elegant than merely examining
> the file name for a "jpg" or "gif"  extension.

Look at the first few bytes of the file. A GIF file will start with
the bytes `GIF87a' or `GIF89a'. A JPEG file will have the bytes `JFIF' 
at offset 6.

However, you should generally use the extension instead. Not only is
it faster than opening every file, but the extension indicates whether
the file is meant to be treated as a GIF or JPEG. It's possible that
some other type of file could contain the above byte sequences by
coincidence.

-- 
Glynn Clements <[EMAIL PROTECTED]>

Reply via email to