Forum Moderators: coopster

Message Too Old, No Replies

Detecting MIME of sending file

         

orion_rus

1:08 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Hello world i need to know how i can find out is the sending file an image or not?
Thanks for helping me.

dreamcatcher

1:36 pm on Mar 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Couple of ways you could do this I think. Firstly, check the file against its mime type or check the file extension if you only want to allow certain files.

I usually check that the file extension is a .jpg, .png or .gif like this:

$filename = "picture.gif";

$extensions = array('.JPG', '.jpg', '.GIF', '.gif', '.png', '.PNG');

$ext = strrchr($filename, '.');

if (in_array($ext, $extensions))
{
//valid file type
}
else
{
//not valid
}

You can use other functions, but this one works ok for me. You can do the same with mime types. Store the allowable ones in an array, then check from there.

Hope that helps.

dc

orion_rus

2:26 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



Ok) thank you very much

frizhard

5:32 pm on Mar 1, 2005 (gmt 0)

10+ Year Member



you can use function getimagesize() [us2.php.net]

it will return FALSE if your file is not a valid image