Checking if a file is an image

I got a file upload form (in asp), besides of checking if the extension is .jpg .bmp etc, how do i check if the file really is an image? so pple wont be able to change an exe file to jpg and upload it right away…

Thanks in advance,

PHP has a function called getimagesize() which returns more than just the length and width of an image which can be used to determine if a file is an image or not.

I would expect ASP to have a similar function - but I went to the PHP school :teach:

This is best done on the server side, which does mean the file will be uploaded. In the future, you’ll be able to check before the file is uploaded. For example, with Firefox you can actually show the user a thumbnail of the picture and get information on the file using the FileReader interface. There’s a number of examples for handling files on the client browser here (scroll down to the “Example: Showing thumbnails” bit).

Unfortunately of course browser support is not complete for this, so it isn’t too useful yet. In any case, it wouldn’t be 100% reliable in real-world use, as javascript is never 100% secure with anything - you would still need to check the mime type of the file on the server (or, just the image dimensions - that’ll tell you if it’s an image).