Page 1 of 1

Avatar validation

Posted: Tue Jun 08, 2004 5:49 pm
by Joe
I was wondering if anyone knew any method to check image validation. For example if someone enters an avatar url the script checks to see if it ends in .jpg, .gif or .bmp

I thought ereg() but im not too sure on the workaround of that!

Regards


Joe 8)

Posted: Tue Jun 08, 2004 5:55 pm
by patrikG
untested and off the top of my head:

Code: Select all

$wildcard = preg_match("/(\.gif|\.jpg|\.bmp|\.png)/i",$filename,$matches);
print_r($matches[1]);

Posted: Tue Jun 08, 2004 6:24 pm
by tim
that will work

.ai, .jpeg can/should be added

Posted: Tue Jun 08, 2004 7:01 pm
by feyd
this may be slightly better:

Code: Select all

function validFilename($filename)
{
  $exts = array('jpe?g','gif','bmp','png','ai');
  $exts = implode('|',$exts);

  return (bool)preg_match("/\.($exts)$/i",$filename);
}
I can write up something to check the actual image data of each of those, if you want it as well.