Re: Checking if an image
From: Ed Astle (REEMOVE_ed_at_REEMOVE_thesignpost.demon.co.uk)
Date: 04/20/04
- Next message: Jeff Bennett: "Re: Multi level Undo"
- Previous message: none: "test"
- In reply to: Steve Peterson: "Checking if an image"
- Next in thread: Justin Rogers: "Re: Checking if an image"
- Reply: Justin Rogers: "Re: Checking if an image"
- Reply: Steve Peterson: "Re: Checking if an image"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 20 Apr 2004 01:32:46 +0100
I had to implement the exact same thing under ASP a few years ago.
I used FindMimeFromData(), which is part of the Internet development stuff
(urlmon.h). It checks the actual content of a data buffer or a url to
determine what the mime type of the data is. From what I remember IE knows
what the initial chunk of various file types "looks like". Jpgs have one
type of header, exe another etc. Give it at least 512 bytes from the front
of a file and it should be able to figure out what it is.
As for doing the same under dotnet - not sure. A quick seach in msdn brings
up stuff like HttpPostedFile.ContentType. That may just report the HTTP
"content-type" field (that the posting brower would set) or it may also
check the actual content - you'll have to try it.
Generally you want to determine the mime type (mime = Multipurpose Internet
Mail Extensions). I know you're not doing email but "mime type" is what
you're after.
BTW - you can explicitly set the "accept" types to prevent the brower
posting stuff the server doesn't want. The web server informs the browser
what mime types are acceptable. See HttpWebRequest.Accept etc. eg
accept="image/jpeg,image/tiff" or "image/*" (can't remember if its ',' or
';' separators). It's still important to do the validation you describe
though.
Regards,
Ed.
"Steve Peterson" <speterson@arrakis.es> wrote in message
news:%23cNh71kJEHA.2244@tk2msftngp13.phx.gbl...
> Hi
>
> I have an ASP.NET where users can upload images to the server. I've
already
> implemented business logic that checks the file extension of the files
> uploaded to make sure they are of an acceptable image type. However, it
> occured to me that a devious user might simply give some non image (Like
an
> .exe) file to an image extension, upload it, and then cause havoc latter
> on.
>
> So, what I need to do is implement business logic that makes sure they
file
> uploaded IS an image file before saving to the server. I'm not familiar
with
> working with graphics, but I figure there must be some method in .NET that
> returns a boolean value if the file is an image format or something along
> those lines..
>
> Can anyone help me out??
> TIA
> Steve
- Next message: Jeff Bennett: "Re: Multi level Undo"
- Previous message: none: "test"
- In reply to: Steve Peterson: "Checking if an image"
- Next in thread: Justin Rogers: "Re: Checking if an image"
- Reply: Justin Rogers: "Re: Checking if an image"
- Reply: Steve Peterson: "Re: Checking if an image"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|